#!/usr/bin/env node
let input = ''
process.stdin.on('data', (chunk) => (input += chunk))
process.stdin.on('end', () => {
  const data = JSON.parse(input)
  const model = data.model?.display_name || '?'
  const pct = Math.floor(data.context_window?.used_percentage || 0)

  const DIM = '\x1b[90m',
    RESET = '\x1b[0m'

  const ctxSize = data.context_window?.context_window_size || 0
  const usedTokens = Math.round((ctxSize * pct) / 100)
  const rounded = Math.round(usedTokens / 100) * 100
  const tokenStr = rounded >= 1000 ? (rounded / 1000).toFixed(1).replace(/\.0$/, '') + 'k' : String(rounded)

  console.log(`${DIM}[${RESET}${model}${DIM}]${RESET} ${tokenStr} Tokens`)
})
