mirror of
https://github.com/jarrodwatts/claude-hud.git
synced 2026-05-21 15:52:37 +00:00
New default: model+project on line 1, context+usage bars combined on line 2. All optional features (tools, agents, todos) hidden by default with setup onboarding step to enable them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49 lines
2.2 KiB
JavaScript
49 lines
2.2 KiB
JavaScript
import { getContextPercent, getBufferedPercent, getTotalTokens } from '../../stdin.js';
|
|
import { coloredBar, dim, getContextColor, RESET } from '../colors.js';
|
|
const DEBUG = process.env.DEBUG?.includes('claude-hud') || process.env.DEBUG === '*';
|
|
export function renderIdentityLine(ctx) {
|
|
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 display = ctx.config?.display;
|
|
const contextValueMode = display?.contextValue ?? 'percent';
|
|
const contextValue = formatContextValue(ctx, percent, contextValueMode);
|
|
const contextValueDisplay = `${getContextColor(percent)}${contextValue}${RESET}`;
|
|
let line = display?.showContextBar !== false
|
|
? `${dim('Context')} ${coloredBar(percent)} ${contextValueDisplay}`
|
|
: `${dim('Context')} ${contextValueDisplay}`;
|
|
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();
|
|
}
|
|
function formatContextValue(ctx, percent, mode) {
|
|
if (mode === 'tokens') {
|
|
const totalTokens = getTotalTokens(ctx.stdin);
|
|
const size = ctx.stdin.context_window?.context_window_size ?? 0;
|
|
if (size > 0) {
|
|
return `${formatTokens(totalTokens)}/${formatTokens(size)}`;
|
|
}
|
|
return formatTokens(totalTokens);
|
|
}
|
|
return `${percent}%`;
|
|
}
|
|
//# sourceMappingURL=identity.js.map
|