()
| 3 | import { Box, Text } from '../ink.js'; |
| 4 | import { formatFileSize } from '../utils/format.js'; |
| 5 | export function MemoryUsageIndicator(): React.ReactNode { |
| 6 | // Ant-only: the /heapdump link is an internal debugging aid. Gating before |
| 7 | // the hook means the 10s polling interval is never set up in external builds. |
| 8 | // USER_TYPE is a build-time constant, so the hook call below is either always |
| 9 | // reached or dead-code-eliminated — never conditional at runtime. |
| 10 | if (("external" as string) !== 'ant') { |
| 11 | return null; |
| 12 | } |
| 13 | |
| 14 | // eslint-disable-next-line react-hooks/rules-of-hooks |
| 15 | // biome-ignore lint/correctness/useHookAtTopLevel: USER_TYPE is a build-time constant |
| 16 | const memoryUsage = useMemoryUsage(); |
| 17 | if (!memoryUsage) { |
| 18 | return null; |
| 19 | } |
| 20 | const { |
| 21 | heapUsed, |
| 22 | status |
| 23 | } = memoryUsage; |
| 24 | |
| 25 | // Only show indicator when memory usage is high or critical |
| 26 | if (status === 'normal') { |
| 27 | return null; |
| 28 | } |
| 29 | const formattedSize = formatFileSize(heapUsed); |
| 30 | const color = status === 'critical' ? 'error' : 'warning'; |
| 31 | return <Box> |
| 32 | <Text color={color} wrap="truncate"> |
| 33 | High memory usage ({formattedSize}) · /heapdump |
| 34 | </Text> |
| 35 | </Box>; |
| 36 | } |
nothing calls this directly
no test coverage detected