{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink/tool-approval",
  "title": "Tool Approval",
  "description": "Interactive approval prompt for AI tool calls with risk-level badge, args display, and auto-deny timeout",
  "dependencies": [
    "ink"
  ],
  "registryDependencies": [
    "https://termcn.dev/r/ink/interaction.json",
    "https://termcn.dev/r/ink/terminal-style.json",
    "https://termcn.dev/r/ink/use-interval.json",
    "https://termcn.dev/r/ink/use-theme.json",
    "https://termcn.dev/r/ink/use-unicode.json"
  ],
  "files": [
    {
      "path": "registry/ui/tool-approval.tsx",
      "content": "import { useIsScreenReaderEnabled, Box, Text } from \"ink\";\nimport React, { useState, useEffect, useRef } from \"react\";\n\nimport {\n  isActivationKey,\n  useInteraction,\n} from \"@/hooks/use-interaction\";\nimport type { InteractionProps } from \"@/hooks/use-interaction\";\nimport { useInterval } from \"@/hooks/use-interval\";\nimport { useTheme } from \"@/hooks/use-theme\";\nimport { useUnicode } from \"@/hooks/use-unicode\";\nimport { resolveBorderStyle } from \"@/lib/terminal-style\";\n\nexport type RiskLevel = \"low\" | \"medium\" | \"high\";\n\nexport interface ToolApprovalProps extends InteractionProps {\n  name: string;\n  description?: string;\n  args?: Record<string, unknown>;\n  risk?: RiskLevel;\n  onApprove?: () => void;\n  onDeny?: () => void;\n  onAlwaysAllow?: () => void;\n  timeout?: number;\n  \"aria-label\"?: string;\n}\n\nexport const ToolApproval = ({\n  name,\n  description,\n  args,\n  risk = \"low\",\n  onApprove,\n  onDeny,\n  onAlwaysAllow,\n  timeout,\n  id,\n  autoFocus,\n  isActive = true,\n  disabled,\n  \"aria-label\": ariaLabel,\n}: ToolApprovalProps) => {\n  const unicode = useUnicode();\n  const theme = useTheme();\n  const isScreenReaderEnabled = useIsScreenReaderEnabled();\n  const [remaining, setRemaining] = useState(timeout ?? 0);\n  const [activeAction, setActiveAction] = useState(0);\n  const onDenyRef = useRef(onDeny);\n\n  useEffect(() => {\n    onDenyRef.current = onDeny;\n  }, [onDeny]);\n\n  useEffect(() => {\n    if (!timeout || !isActive || disabled) {\n      return;\n    }\n    setRemaining(timeout);\n    const id = setTimeout(() => onDenyRef.current?.(), timeout * 1000);\n    return () => clearTimeout(id);\n  }, [disabled, isActive, timeout]);\n\n  useInterval(() => setRemaining((value) => Math.max(0, value - 1)), 1000, {\n    isActive: Boolean(timeout && remaining > 0 && isActive && !disabled),\n  });\n\n  const actions = [\n    { label: \"Approve\", run: onApprove, shortcut: \"y\" },\n    { label: \"Deny\", run: onDeny, shortcut: \"n\" },\n    ...(onAlwaysAllow\n      ? [{ label: \"Always allow\", run: onAlwaysAllow, shortcut: \"a\" }]\n      : []),\n  ];\n\n  const { isFocused } = useInteraction(\n    (input, key) => {\n      if (input === \"y\" || input === \"Y\") {\n        onApprove?.();\n      } else if (input === \"n\" || input === \"N\") {\n        onDeny?.();\n      } else if ((input === \"a\" || input === \"A\") && onAlwaysAllow) {\n        onAlwaysAllow();\n      } else if (key.leftArrow || key.upArrow) {\n        setActiveAction((index) => Math.max(0, index - 1));\n      } else if (key.rightArrow || key.downArrow) {\n        setActiveAction((index) => Math.min(actions.length - 1, index + 1));\n      } else if (key.home) {\n        setActiveAction(0);\n      } else if (key.end) {\n        setActiveAction(actions.length - 1);\n      } else if (isActivationKey(input, key)) {\n        actions[activeAction]?.run?.();\n      }\n    },\n    { autoFocus, disabled, id, isActive }\n  );\n\n  const riskBorderColor: Record<RiskLevel, string> = {\n    high: theme.colors.error ?? \"red\",\n    low: theme.colors.success ?? \"green\",\n    medium: theme.colors.warning ?? \"yellow\",\n  };\n\n  const riskLabel: Record<RiskLevel, string> = {\n    high: \"HIGH\",\n    low: \"LOW\",\n    medium: \"MEDIUM\",\n  };\n\n  const riskLabelColor: Record<RiskLevel, string> = {\n    high: theme.colors.error ?? \"red\",\n    low: theme.colors.success ?? \"green\",\n    medium: theme.colors.warning ?? \"yellow\",\n  };\n\n  const borderColor = riskBorderColor[risk];\n\n  return (\n    <Box\n      flexDirection=\"column\"\n      borderStyle={resolveBorderStyle(\n        isScreenReaderEnabled ? undefined : \"round\",\n        unicode\n      )}\n      borderColor={borderColor}\n      paddingX={1}\n      paddingY={0}\n      aria-role=\"toolbar\"\n      aria-state={{ disabled: disabled || undefined }}\n    >\n      <Text\n        aria-label={\n          ariaLabel ??\n          `Tool approval: ${name}. ${riskLabel[risk]} risk.${timeout ? ` Auto-deny in ${timeout} seconds.` : \"\"}`\n        }\n      >\n        {\"\"}\n      </Text>\n      <Box gap={2}>\n        <Text bold color={theme.colors.foreground}>\n          Tool Approval Required\n        </Text>\n        <Text bold color={riskLabelColor[risk]}>\n          [{riskLabel[risk]} RISK]\n        </Text>\n        {timeout && remaining > 0 && (\n          <Text color={theme.colors.warning ?? \"yellow\"} dimColor>\n            Auto-deny in {remaining}s\n          </Text>\n        )}\n      </Box>\n\n      <Box flexDirection=\"column\" marginTop={1}>\n        <Box gap={1}>\n          <Text color={theme.colors.mutedForeground}>Tool:</Text>\n          <Text bold color={theme.colors.primary}>\n            {name}\n          </Text>\n        </Box>\n        {description && (\n          <Box gap={1}>\n            <Text color={theme.colors.mutedForeground}>Description:</Text>\n            <Text dimColor>{description}</Text>\n          </Box>\n        )}\n      </Box>\n\n      {args && Object.keys(args).length > 0 && (\n        <Box flexDirection=\"column\" marginTop={1}>\n          <Text color={theme.colors.mutedForeground} dimColor>\n            Arguments:\n          </Text>\n          {Object.entries(args).map(([k, v]) => (\n            <Box key={k} gap={1} paddingLeft={2}>\n              <Text color={theme.colors.accent}>{k}:</Text>\n              <Text dimColor>{JSON.stringify(v)}</Text>\n            </Box>\n          ))}\n        </Box>\n      )}\n\n      <Box gap={2} marginTop={1}>\n        {actions.map((action, index) => {\n          const focused = activeAction === index;\n          const color =\n            action.shortcut === \"y\"\n              ? (theme.colors.success ?? \"green\")\n              : action.shortcut === \"n\"\n                ? (theme.colors.error ?? \"red\")\n                : (theme.colors.warning ?? \"yellow\");\n          return (\n            <Box\n              key={action.shortcut}\n              aria-role=\"button\"\n              aria-label={action.label}\n              aria-state={{ disabled: disabled || undefined }}\n            >\n              <Text color={color} bold inverse={focused}>\n                {focused ? \"> \" : \"\"}[{action.shortcut}] {action.label}\n              </Text>\n            </Box>\n          );\n        })}\n      </Box>\n    </Box>\n  );\n};\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "ai"
  ],
  "type": "registry:ui"
}