tokens-metric 0.4.7 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/tui/index.js +15 -4
  2. package/package.json +1 -1
package/dist/tui/index.js CHANGED
@@ -327,7 +327,7 @@ function BarRow({ label, value, max, total, color, cost, }) {
327
327
  }
328
328
  // ── History panel ────────────────────────────────────────────────────────────
329
329
  function HistoryPanel({ history }) {
330
- return (_jsxs(Box, { borderStyle: "round", borderColor: "blue", paddingX: 1, flexDirection: "column", width: "100%", children: [_jsxs(Text, { bold: true, color: "blue", children: ['Usage history', _jsx(Text, { bold: false, color: "blue", children: " \u00B7 refreshes every 60s" })] }), !history ? (_jsx(Text, { dimColor: true, children: "Scanning\u2026" })) : history.scannedFiles === 0 ? (_jsx(Text, { dimColor: true, children: "No transcripts found." })) : (_jsxs(_Fragment, { children: [_jsx(Box, { marginTop: 1, children: _jsx(DualBarChart, { days: history.last7Days, now: history.generatedAt }) }), _jsxs(Box, { marginTop: 1, children: [_jsx(HistoryRow, { label: "", today: "Today", d7: "7d", d30: "30d", dim: true }), _jsx(HistoryRow, { label: "Tokens ", today: fmtNumber(bucketTokens(history.today)), d7: fmtNumber(bucketTokens(history.d7)), d30: fmtNumber(bucketTokens(history.d30)) }), _jsx(HistoryRow, { label: "Cost~ ", today: fmtCost(bucketCostUSD(history.today)), d7: fmtCost(bucketCostUSD(history.d7)), d30: fmtCost(bucketCostUSD(history.d30)) }), _jsx(HistoryRow, { label: "Sessions", today: String(history.today.sessions.size), d7: String(history.d7.sessions.size), d30: String(history.d30.sessions.size) })] }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: [`scanned ${history.scannedFiles} transcripts`, history.oldestMtimeMs !== null &&
330
+ return (_jsxs(Box, { borderStyle: "round", borderColor: "blue", paddingX: 1, flexDirection: "column", width: "100%", children: [_jsxs(Text, { bold: true, color: "blue", children: ['Usage history', _jsx(Text, { bold: false, color: "blue", children: " \u00B7 refreshes every 60s" })] }), !history ? (_jsx(Text, { dimColor: true, children: "Scanning\u2026" })) : history.scannedFiles === 0 ? (_jsx(Text, { dimColor: true, children: "No transcripts found." })) : (_jsxs(_Fragment, { children: [_jsx(Box, { marginTop: 1, children: _jsx(DualBarChart, { days: history.last7Days, now: history.generatedAt }) }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(HistoryRow, { label: "", today: "Today", d7: "7d", d30: "30d", dim: true }), _jsx(HistoryRow, { label: "Tokens ", today: fmtNumber(bucketTokens(history.today)), d7: fmtNumber(bucketTokens(history.d7)), d30: fmtNumber(bucketTokens(history.d30)) }), _jsx(HistoryRow, { label: "Cost~ ", today: fmtCost(bucketCostUSD(history.today)), d7: fmtCost(bucketCostUSD(history.d7)), d30: fmtCost(bucketCostUSD(history.d30)) }), _jsx(HistoryRow, { label: "Sessions", today: String(history.today.sessions.size), d7: String(history.d7.sessions.size), d30: String(history.d30.sessions.size) })] }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: [`scanned ${history.scannedFiles} transcripts`, history.oldestMtimeMs !== null &&
331
331
  ` · data since ${fmtDate(history.oldestMtimeMs)} (${daysAgo(history.oldestMtimeMs, history.generatedAt)} days)`] }) })] }))] }));
332
332
  }
333
333
  // ── Dual bar chart ────────────────────────────────────────────────────────────
@@ -349,7 +349,11 @@ function DualBarChart({ days, now }) {
349
349
  const maxTokens = Math.max(1, ...days.flatMap((d) => [claudeTokens(d.byModel), codexTokens(d.byModel)]));
350
350
  const DAY_LABELS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
351
351
  const todayStart = (() => { const d = new Date(now); d.setHours(0, 0, 0, 0); return d.getTime(); })();
352
- return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, dimColor: true, children: 'last 7 days' }), days.map((day) => {
352
+ const fmtDay = (ms) => {
353
+ const d = new Date(ms);
354
+ return `${String(d.getMonth() + 1).padStart(2, '0')}/${String(d.getDate()).padStart(2, '0')}`;
355
+ };
356
+ return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { dimColor: true, children: ["last 7 days \u00B7 ", _jsx(Text, { color: "cyan", children: "\u2588" }), " claude ", _jsx(Text, { color: "magenta", children: "\u2588" }), " codex"] }), days.map((day) => {
353
357
  const ct = claudeTokens(day.byModel);
354
358
  const cxt = codexTokens(day.byModel);
355
359
  const cc = claudeCost(day.byModel);
@@ -357,9 +361,16 @@ function DualBarChart({ days, now }) {
357
361
  .filter(([m]) => m === 'codex')
358
362
  .reduce((s, [m, u]) => s + (estimateCostUSD(m, u) ?? 0), 0);
359
363
  const isToday = day.dayStart === todayStart;
360
- const label = isToday ? 'today' : DAY_LABELS[new Date(day.dayStart).getDay()];
364
+ const dayName = isToday ? 'today' : DAY_LABELS[new Date(day.dayStart).getDay()];
365
+ const label = `${dayName.padEnd(5)} ${fmtDay(day.dayStart)}`;
361
366
  const hasData = ct > 0 || cxt > 0;
362
- return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { bold: isToday, color: isToday ? 'white' : undefined, children: [label.padEnd(6), !hasData && _jsx(Text, { dimColor: true, children: " no data" })] }), ct > 0 && (_jsxs(Text, { children: [_jsx(Text, { dimColor: true, children: ' claude ' }), _jsx(Text, { color: "cyan", children: solidBar(ct / maxTokens, CHART_BAR_WIDTH) }), _jsx(Text, { children: ' ' }), _jsx(Text, { bold: true, children: fmtNumber(ct).padStart(7) }), cc > 0 && _jsx(Text, { dimColor: true, children: ` ~${fmtUSD(cc)}` })] })), cxt > 0 && (_jsxs(Text, { children: [_jsx(Text, { dimColor: true, children: ' codex ' }), _jsx(Text, { color: "magenta", children: solidBar(cxt / maxTokens, CHART_BAR_WIDTH) }), _jsx(Text, { children: ' ' }), _jsx(Text, { bold: true, children: fmtNumber(cxt).padStart(7) }), cxc > 0 && _jsx(Text, { dimColor: true, children: ` ~${fmtUSD(cxc)}` })] }))] }, day.dayStart));
367
+ if (!hasData) {
368
+ return (_jsxs(Text, { dimColor: true, children: [label, " \u2500"] }, day.dayStart));
369
+ }
370
+ const labelPad = ' '.repeat(label.length + 2);
371
+ return (_jsxs(Box, { flexDirection: "column", children: [ct > 0 && (_jsxs(Text, { children: [_jsxs(Text, { bold: isToday, color: isToday ? 'white' : undefined, children: [label, " "] }), _jsx(Text, { dimColor: true, children: "claude " }), _jsx(Text, { color: "cyan", children: solidBar(ct / maxTokens, CHART_BAR_WIDTH) }), _jsx(Text, { children: " " }), _jsx(Text, { bold: true, children: fmtNumber(ct).padStart(7) }), cc > 0 && _jsx(Text, { dimColor: true, children: ` ~${fmtUSD(cc)}` })] })), cxt > 0 && (_jsxs(Text, { children: [ct > 0
372
+ ? _jsx(Text, { children: labelPad })
373
+ : _jsxs(Text, { bold: isToday, color: isToday ? 'white' : undefined, children: [label, " "] }), _jsx(Text, { dimColor: true, children: "codex " }), _jsx(Text, { color: "magenta", children: solidBar(cxt / maxTokens, CHART_BAR_WIDTH) }), _jsx(Text, { children: " " }), _jsx(Text, { bold: true, children: fmtNumber(cxt).padStart(7) }), cxc > 0 && _jsx(Text, { dimColor: true, children: ` ~${fmtUSD(cxc)}` })] }))] }, day.dayStart));
363
374
  })] }));
364
375
  }
365
376
  function solidBar(ratio, width) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokens-metric",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "Real-time token usage meter for Claude Code — statusline + Ink TUI.",
5
5
  "type": "module",
6
6
  "bin": {