mirror of
https://github.com/jarrodwatts/claude-hud.git
synced 2026-05-21 07:22:44 +00:00
Major rewrite from split-pane TUI to multi-line statusline: - Remove hooks/, tui/, scripts/ directories - Add new src/ structure with TypeScript - Implement stdin JSON parser (native model/context data) - Implement transcript JSONL parser (tools, agents, todos) - Implement render system with 4 lines: - Session: model, context bar, rules, MCPs, duration - Tools: running + completed with counts - Agents: type, model, description, elapsed - Todos: current task with progress - Add context warning thresholds (70%, 85%, 95%) - Show context breakdown at high usage - Update plugin.json with statusLine config 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import type { StdinData } from './types.js';
|
|
|
|
export async function readStdin(): Promise<StdinData | null> {
|
|
if (process.stdin.isTTY) {
|
|
return null;
|
|
}
|
|
|
|
const chunks: string[] = [];
|
|
|
|
try {
|
|
process.stdin.setEncoding('utf8');
|
|
for await (const chunk of process.stdin) {
|
|
chunks.push(chunk as string);
|
|
}
|
|
const raw = chunks.join('');
|
|
if (!raw.trim()) {
|
|
return null;
|
|
}
|
|
return JSON.parse(raw) as StdinData;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function getContextPercent(stdin: StdinData): number {
|
|
const usage = stdin.context_window?.current_usage;
|
|
const size = stdin.context_window?.context_window_size;
|
|
|
|
if (!usage || !size || size === 0) {
|
|
return 0;
|
|
}
|
|
|
|
const totalTokens =
|
|
(usage.input_tokens ?? 0) +
|
|
(usage.cache_creation_input_tokens ?? 0) +
|
|
(usage.cache_read_input_tokens ?? 0);
|
|
|
|
return Math.round((totalTokens / size) * 100);
|
|
}
|
|
|
|
export function getModelName(stdin: StdinData): string {
|
|
return stdin.model?.display_name ?? stdin.model?.id ?? 'Unknown';
|
|
}
|