import { getContextPercent, getBufferedPercent, getModelName } from '../../stdin.js'; import { coloredBar, cyan, dim, getContextColor, RESET } from '../colors.js'; const DEBUG = process.env.DEBUG?.includes('claude-hud') || process.env.DEBUG === '*'; export function renderIdentityLine(ctx) { const model = getModelName(ctx.stdin); const rawPercent = getContextPercent(ctx.stdin); const bufferedPercent = getBufferedPercent(ctx.stdin); const autocompactMode = ctx.config?.display?.autocompactBuffer ?? 'enabled'; const percent = autocompactMode === 'disabled' ? rawPercent : bufferedPercent; if (DEBUG && autocompactMode === 'disabled') { console.error(`[claude-hud:context] autocompactBuffer=disabled, showing raw ${rawPercent}% (buffered would be ${bufferedPercent}%)`); } const bar = coloredBar(percent); const display = ctx.config?.display; const parts = []; const planName = display?.showUsage !== false ? ctx.usageData?.planName : undefined; const modelDisplay = planName ? `${model} | ${planName}` : model; if (display?.showModel !== false && display?.showContextBar !== false) { parts.push(`${cyan(`[${modelDisplay}]`)} ${bar} ${getContextColor(percent)}${percent}%${RESET}`); } else if (display?.showModel !== false) { parts.push(`${cyan(`[${modelDisplay}]`)} ${getContextColor(percent)}${percent}%${RESET}`); } else if (display?.showContextBar !== false) { parts.push(`${bar} ${getContextColor(percent)}${percent}%${RESET}`); } else { parts.push(`${getContextColor(percent)}${percent}%${RESET}`); } if (display?.showDuration !== false && ctx.sessionDuration) { parts.push(dim(`⏱️ ${ctx.sessionDuration}`)); } let line = parts.join(' | '); if (display?.showTokenBreakdown !== false && percent >= 85) { const usage = ctx.stdin.context_window?.current_usage; if (usage) { const input = formatTokens(usage.input_tokens ?? 0); const cache = formatTokens((usage.cache_creation_input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0)); line += dim(` (in: ${input}, cache: ${cache})`); } } return line; } function formatTokens(n) { if (n >= 1000000) { return `${(n / 1000000).toFixed(1)}M`; } if (n >= 1000) { return `${(n / 1000).toFixed(0)}k`; } return n.toString(); } //# sourceMappingURL=identity.js.map