@tokenboard/cli 0.1.3 → 0.1.4

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.
package/dist/cli.js CHANGED
@@ -1073,22 +1073,69 @@ function summarize(records, prices) {
1073
1073
  // src/render/terminal-style.ts
1074
1074
  init_esm_shims();
1075
1075
  var import_picocolors = __toESM(require_picocolors(), 1);
1076
+ function detectColorLevel(i) {
1077
+ const force = i.forceColor;
1078
+ if (force !== void 0 && force !== "") {
1079
+ const n = Number(force);
1080
+ if (n === 0) return 0;
1081
+ if (n === 1 || n === 2 || n === 3) return n;
1082
+ return 3;
1083
+ }
1084
+ const ct = (i.colorterm ?? "").toLowerCase();
1085
+ if (ct === "truecolor" || ct === "24bit") return 3;
1086
+ const term = (i.term ?? "").toLowerCase();
1087
+ if (term === "xterm-kitty" || term === "ghostty" || term === "wezterm") return 3;
1088
+ if (/-256(color)?$/.test(term)) return 2;
1089
+ return 1;
1090
+ }
1076
1091
  function resolveStyle(inputs) {
1092
+ const color = inputs.isTTY && !inputs.noColorEnv && !inputs.noColorFlag;
1077
1093
  return {
1078
- color: inputs.isTTY && !inputs.noColorEnv && !inputs.noColorFlag,
1094
+ color,
1095
+ level: color ? detectColorLevel(inputs) : 0,
1096
+ // master gate: NO_COLOR/non-TTY => 0
1079
1097
  width: Math.min(inputs.columns ?? 80, 80),
1080
1098
  ascii: inputs.asciiFlag
1081
1099
  };
1082
1100
  }
1101
+ var CORAL_TC = "\x1B[38;2;204;120;92m";
1102
+ var CORAL_HI_TC = "\x1B[38;2;214;141;114m";
1103
+ var RESET_FG = "\x1B[39m";
1104
+ var CORAL_256 = "\x1B[38;5;173m";
1105
+ var CORAL_HI_256 = "\x1B[38;5;180m";
1083
1106
  function styler(style) {
1084
1107
  const on = style.color;
1108
+ const lvl = style.level;
1109
+ const coral = (s) => {
1110
+ if (lvl >= 3) return CORAL_TC + s + RESET_FG;
1111
+ if (lvl === 2) return CORAL_256 + s + RESET_FG;
1112
+ if (lvl === 1) return import_picocolors.default.yellow(s);
1113
+ return s;
1114
+ };
1115
+ const coralHi = (s) => {
1116
+ if (lvl >= 3) return CORAL_HI_TC + s + RESET_FG;
1117
+ if (lvl === 2) return CORAL_HI_256 + s + RESET_FG;
1118
+ if (lvl === 1) return import_picocolors.default.yellow(s);
1119
+ return s;
1120
+ };
1085
1121
  return {
1086
1122
  dim: (s) => on ? import_picocolors.default.dim(s) : s,
1087
1123
  bold: (s) => on ? import_picocolors.default.bold(s) : s,
1088
1124
  green: (s) => on ? import_picocolors.default.green(s) : s,
1089
1125
  red: (s) => on ? import_picocolors.default.red(s) : s,
1090
1126
  cyan: (s) => on ? import_picocolors.default.cyan(s) : s,
1091
- inverse: (s) => on ? import_picocolors.default.inverse(s) : s
1127
+ inverse: (s) => on ? import_picocolors.default.inverse(s) : s,
1128
+ coral,
1129
+ coralHi,
1130
+ // Accent a busy day WITHOUT ever dimming real data: a normal/low day stays DEFAULT full-weight
1131
+ // text (readable), a busy day (t >= 0.34 of the per-series max) gets coral, the peak (t > 0.67)
1132
+ // gets bold hi-coral. Identity at level 0. "Tasteful: accent peaks only."
1133
+ accentByLevel: (s, t) => {
1134
+ if (lvl === 0) return s;
1135
+ if (t > 0.67) return import_picocolors.default.bold(coralHi(s));
1136
+ if (t >= 0.34) return coral(s);
1137
+ return s;
1138
+ }
1092
1139
  };
1093
1140
  }
1094
1141
 
@@ -1742,17 +1789,22 @@ function formatApproxUsd(n) {
1742
1789
  init_esm_shims();
1743
1790
  var GLYPHS = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
1744
1791
  var ASCII_GLYPHS = ["_", ".", ".", "-", "-", "=", "=", "#"];
1745
- function sparkline(values, ascii = false) {
1792
+ function sparkline(values, ascii = false, colorize) {
1746
1793
  const glyphs2 = ascii ? ASCII_GLYPHS : GLYPHS;
1747
1794
  if (values.length === 0) return "";
1748
1795
  const min = Math.min(...values);
1749
1796
  const max = Math.max(...values);
1750
1797
  const range = max - min;
1751
- if (range === 0) return glyphs2[0].repeat(values.length);
1752
- return values.map((v) => {
1753
- const idx = Math.round((v - min) / range * (glyphs2.length - 1));
1754
- return glyphs2[idx];
1755
- }).join("");
1798
+ const pick = (v) => range === 0 ? glyphs2[0] : glyphs2[Math.round((v - min) / range * (glyphs2.length - 1))];
1799
+ return values.map((v, i) => colorize ? colorize(pick(v), i) : pick(v)).join("");
1800
+ }
1801
+
1802
+ // src/render/model-display.ts
1803
+ init_esm_shims();
1804
+ function displayModel(model) {
1805
+ const m = model.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)(?:-\d+)?$/i);
1806
+ if (m) return `${m[1].toLowerCase()}-${m[2]}.${m[3]}`;
1807
+ return model.startsWith("claude-") ? model.slice("claude-".length) : model;
1756
1808
  }
1757
1809
 
1758
1810
  // src/render/local-preview.ts
@@ -1761,10 +1813,10 @@ function renderLocalPreview(summary, style) {
1761
1813
  const g = glyphs(style.ascii);
1762
1814
  const lines = [];
1763
1815
  lines.push(
1764
- c.bold(`you burned ${humanizeTokens(summary.totalTokens)} tokens`) + ` \xB7 ${formatApproxUsd(summary.totalCostUsd)} est`
1816
+ c.dim("you've burned ") + c.bold(c.coral(humanizeTokens(summary.totalTokens))) + c.dim(" tokens all-time \xB7 ") + c.coral(formatApproxUsd(summary.totalCostUsd)) + c.dim(" est")
1765
1817
  );
1766
1818
  lines.push("");
1767
- lines.push(c.dim("\u{1FA99} tokenboard \xB7 your local usage by day"));
1819
+ lines.push(c.coral("\u{1FA99} tokenboard") + c.dim(" \xB7 your usage by day"));
1768
1820
  const headers = ["date", "tokens", "~$ est"];
1769
1821
  const aligns = ["left", "right", "right"];
1770
1822
  const bodyRows = summary.perDay.map((d) => [
@@ -1779,19 +1831,44 @@ function renderLocalPreview(summary, style) {
1779
1831
  );
1780
1832
  const cellAlign = (i) => aligns[i] ?? "left";
1781
1833
  const width = (i) => colWidths[i] ?? 1;
1782
- const renderRow = (cells) => row(cells.map((cell, i) => padCell(cell, width(i), cellAlign(i))), g);
1783
- lines.push(rule(colWidths, "top", g));
1784
- lines.push(renderRow(headers));
1785
- lines.push(rule(colWidths, "mid", g));
1786
- for (const r of bodyRows) lines.push(renderRow(r));
1787
- lines.push(rule(colWidths, "mid", g));
1788
- lines.push(renderRow(totalRow));
1789
- lines.push(rule(colWidths, "bottom", g));
1790
- const spark = sparkline(
1791
- summary.perDay.map((d) => d.tokens),
1792
- style.ascii
1834
+ const renderRow = (cells, colorize) => row(
1835
+ cells.map((cell, i) => {
1836
+ const padded = padCell(cell, width(i), cellAlign(i));
1837
+ return colorize ? colorize(padded, i) : padded;
1838
+ }),
1839
+ g
1793
1840
  );
1841
+ const dayTokens = summary.perDay.map((d) => d.tokens);
1842
+ const min = dayTokens.length ? Math.min(...dayTokens) : 0;
1843
+ const max = dayTokens.length ? Math.max(...dayTokens) : 0;
1844
+ const range = max - min;
1845
+ const norm = (v) => range === 0 ? 0 : (v - min) / range;
1846
+ const dimRule = (pos) => c.dim(rule(colWidths, pos, g));
1847
+ lines.push(dimRule("top"));
1848
+ lines.push(renderRow(headers, (p) => c.dim(p)));
1849
+ lines.push(dimRule("mid"));
1850
+ summary.perDay.forEach((d, idx) => {
1851
+ lines.push(
1852
+ renderRow(bodyRows[idx], (p, col) => {
1853
+ if (col === 1) return c.accentByLevel(p, norm(d.tokens));
1854
+ if (col === 2) return c.dim(p);
1855
+ return p;
1856
+ })
1857
+ );
1858
+ });
1859
+ lines.push(dimRule("mid"));
1860
+ lines.push(
1861
+ renderRow(totalRow, (p, col) => {
1862
+ if (col === 0) return c.dim(c.bold(p));
1863
+ if (col === 1) return c.bold(c.coral(p));
1864
+ return c.coral(p);
1865
+ })
1866
+ );
1867
+ lines.push(dimRule("bottom"));
1868
+ const spark = sparkline(dayTokens, style.ascii, (glyph, i) => c.accentByLevel(glyph, norm(dayTokens[i])));
1794
1869
  if (spark) lines.push(c.dim("daily burn ") + spark);
1870
+ const modelStrip = renderModelStrip(summary, c);
1871
+ if (modelStrip) lines.push(modelStrip);
1795
1872
  lines.push(
1796
1873
  c.dim("approx $ is a local estimate from a bundled LiteLLM snapshot \u2014 the server is authoritative")
1797
1874
  );
@@ -1800,6 +1877,20 @@ function renderLocalPreview(summary, style) {
1800
1877
  }
1801
1878
  return lines.join("\n");
1802
1879
  }
1880
+ function renderModelStrip(summary, c) {
1881
+ if (summary.perModel.length === 0) return "";
1882
+ const TOP = 3;
1883
+ const shown = summary.perModel.slice(0, TOP);
1884
+ const parts = shown.map((m, rank) => {
1885
+ const name = displayModel(m.model) + (m.priced ? "" : c.dim("*"));
1886
+ const nameStyled = rank === 0 ? c.coral(name) : name;
1887
+ return `${nameStyled} ${humanizeTokens(m.tokens)} ${c.dim(formatApproxUsd(m.costUsd))}`;
1888
+ });
1889
+ let strip = c.dim("models ") + parts.join(c.dim(" \xB7 "));
1890
+ const extra = summary.perModel.length - shown.length;
1891
+ if (extra > 0) strip += c.dim(` \xB7 +${extra} more`);
1892
+ return strip;
1893
+ }
1803
1894
  var CLAIM_PROMPT = "Sign in with GitHub to claim your spot?";
1804
1895
  var CLAIM_HINT = "\u2192 Claim your spot anytime \u2192 tokenboard claim";
1805
1896
 
@@ -2442,7 +2533,10 @@ async function runPreview(args) {
2442
2533
  noColorEnv: process.env["NO_COLOR"] !== void 0,
2443
2534
  noColorFlag: args.noColor,
2444
2535
  asciiFlag: args.ascii,
2445
- columns: process.stdout.columns
2536
+ columns: process.stdout.columns,
2537
+ colorterm: process.env["COLORTERM"],
2538
+ term: process.env["TERM"],
2539
+ forceColor: process.env["FORCE_COLOR"]
2446
2540
  });
2447
2541
  process.stdout.write(renderLocalPreview(summary, style) + "\n");
2448
2542
  await offerClaim(style);