@tokenboard/cli 0.1.3 → 0.1.5
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 +114 -36
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1027,6 +1027,17 @@ if (provenance_default.priceTableVersion !== PRICE_TABLE_VERSION || provenance_d
|
|
|
1027
1027
|
function recordTokens(r) {
|
|
1028
1028
|
return r.input + r.output + r.cacheRead + r.cacheCreate5m + r.cacheCreate1h;
|
|
1029
1029
|
}
|
|
1030
|
+
function dominantModel(byModel) {
|
|
1031
|
+
let best = "";
|
|
1032
|
+
let bestTokens = -1;
|
|
1033
|
+
for (const [model, tokens] of byModel) {
|
|
1034
|
+
if (tokens > bestTokens || tokens === bestTokens && model < best) {
|
|
1035
|
+
best = model;
|
|
1036
|
+
bestTokens = tokens;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
return best;
|
|
1040
|
+
}
|
|
1030
1041
|
function summarize(records, prices) {
|
|
1031
1042
|
let totalTokens = 0;
|
|
1032
1043
|
let totalCostUsd = 0;
|
|
@@ -1044,9 +1055,10 @@ function summarize(records, prices) {
|
|
|
1044
1055
|
unpricedTokens += tokens;
|
|
1045
1056
|
unpricedModels.add(r.model);
|
|
1046
1057
|
}
|
|
1047
|
-
const d = perDay.get(r.date) ?? { tokens: 0, costUsd: 0 };
|
|
1058
|
+
const d = perDay.get(r.date) ?? { tokens: 0, costUsd: 0, byModel: /* @__PURE__ */ new Map() };
|
|
1048
1059
|
d.tokens += tokens;
|
|
1049
1060
|
d.costUsd += costUsd;
|
|
1061
|
+
d.byModel.set(r.model, (d.byModel.get(r.model) ?? 0) + tokens);
|
|
1050
1062
|
perDay.set(r.date, d);
|
|
1051
1063
|
const t = perTool.get(r.tool) ?? { tokens: 0, costUsd: 0 };
|
|
1052
1064
|
t.tokens += tokens;
|
|
@@ -1064,7 +1076,7 @@ function summarize(records, prices) {
|
|
|
1064
1076
|
anyUnpriced: unpricedModels.size > 0,
|
|
1065
1077
|
unpricedTokens,
|
|
1066
1078
|
unpricedModels: [...unpricedModels].sort(),
|
|
1067
|
-
perDay: [...perDay.entries()].map(([date, v]) => ({ date,
|
|
1079
|
+
perDay: [...perDay.entries()].map(([date, v]) => ({ date, tokens: v.tokens, costUsd: v.costUsd, model: dominantModel(v.byModel) })).sort((a, b) => a.date < b.date ? -1 : 1),
|
|
1068
1080
|
perTool: [...perTool.entries()].map(([tool, v]) => ({ tool, ...v })).sort((a, b) => b.tokens - a.tokens),
|
|
1069
1081
|
perModel: [...perModel.entries()].map(([model, v]) => ({ model, ...v })).sort((a, b) => b.tokens - a.tokens)
|
|
1070
1082
|
};
|
|
@@ -1073,22 +1085,69 @@ function summarize(records, prices) {
|
|
|
1073
1085
|
// src/render/terminal-style.ts
|
|
1074
1086
|
init_esm_shims();
|
|
1075
1087
|
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
1088
|
+
function detectColorLevel(i) {
|
|
1089
|
+
const force = i.forceColor;
|
|
1090
|
+
if (force !== void 0 && force !== "") {
|
|
1091
|
+
const n = Number(force);
|
|
1092
|
+
if (n === 0) return 0;
|
|
1093
|
+
if (n === 1 || n === 2 || n === 3) return n;
|
|
1094
|
+
return 3;
|
|
1095
|
+
}
|
|
1096
|
+
const ct = (i.colorterm ?? "").toLowerCase();
|
|
1097
|
+
if (ct === "truecolor" || ct === "24bit") return 3;
|
|
1098
|
+
const term = (i.term ?? "").toLowerCase();
|
|
1099
|
+
if (term === "xterm-kitty" || term === "ghostty" || term === "wezterm") return 3;
|
|
1100
|
+
if (/-256(color)?$/.test(term)) return 2;
|
|
1101
|
+
return 1;
|
|
1102
|
+
}
|
|
1076
1103
|
function resolveStyle(inputs) {
|
|
1104
|
+
const color = inputs.isTTY && !inputs.noColorEnv && !inputs.noColorFlag;
|
|
1077
1105
|
return {
|
|
1078
|
-
color
|
|
1106
|
+
color,
|
|
1107
|
+
level: color ? detectColorLevel(inputs) : 0,
|
|
1108
|
+
// master gate: NO_COLOR/non-TTY => 0
|
|
1079
1109
|
width: Math.min(inputs.columns ?? 80, 80),
|
|
1080
1110
|
ascii: inputs.asciiFlag
|
|
1081
1111
|
};
|
|
1082
1112
|
}
|
|
1113
|
+
var CORAL_TC = "\x1B[38;2;204;120;92m";
|
|
1114
|
+
var CORAL_HI_TC = "\x1B[38;2;214;141;114m";
|
|
1115
|
+
var RESET_FG = "\x1B[39m";
|
|
1116
|
+
var CORAL_256 = "\x1B[38;5;173m";
|
|
1117
|
+
var CORAL_HI_256 = "\x1B[38;5;180m";
|
|
1083
1118
|
function styler(style) {
|
|
1084
1119
|
const on = style.color;
|
|
1120
|
+
const lvl = style.level;
|
|
1121
|
+
const coral = (s) => {
|
|
1122
|
+
if (lvl >= 3) return CORAL_TC + s + RESET_FG;
|
|
1123
|
+
if (lvl === 2) return CORAL_256 + s + RESET_FG;
|
|
1124
|
+
if (lvl === 1) return import_picocolors.default.yellow(s);
|
|
1125
|
+
return s;
|
|
1126
|
+
};
|
|
1127
|
+
const coralHi = (s) => {
|
|
1128
|
+
if (lvl >= 3) return CORAL_HI_TC + s + RESET_FG;
|
|
1129
|
+
if (lvl === 2) return CORAL_HI_256 + s + RESET_FG;
|
|
1130
|
+
if (lvl === 1) return import_picocolors.default.yellow(s);
|
|
1131
|
+
return s;
|
|
1132
|
+
};
|
|
1085
1133
|
return {
|
|
1086
1134
|
dim: (s) => on ? import_picocolors.default.dim(s) : s,
|
|
1087
1135
|
bold: (s) => on ? import_picocolors.default.bold(s) : s,
|
|
1088
1136
|
green: (s) => on ? import_picocolors.default.green(s) : s,
|
|
1089
1137
|
red: (s) => on ? import_picocolors.default.red(s) : s,
|
|
1090
1138
|
cyan: (s) => on ? import_picocolors.default.cyan(s) : s,
|
|
1091
|
-
inverse: (s) => on ? import_picocolors.default.inverse(s) : s
|
|
1139
|
+
inverse: (s) => on ? import_picocolors.default.inverse(s) : s,
|
|
1140
|
+
coral,
|
|
1141
|
+
coralHi,
|
|
1142
|
+
// Accent a busy day WITHOUT ever dimming real data: a normal/low day stays DEFAULT full-weight
|
|
1143
|
+
// text (readable), a busy day (t >= 0.34 of the per-series max) gets coral, the peak (t > 0.67)
|
|
1144
|
+
// gets bold hi-coral. Identity at level 0. "Tasteful: accent peaks only."
|
|
1145
|
+
accentByLevel: (s, t) => {
|
|
1146
|
+
if (lvl === 0) return s;
|
|
1147
|
+
if (t > 0.67) return import_picocolors.default.bold(coralHi(s));
|
|
1148
|
+
if (t >= 0.34) return coral(s);
|
|
1149
|
+
return s;
|
|
1150
|
+
}
|
|
1092
1151
|
};
|
|
1093
1152
|
}
|
|
1094
1153
|
|
|
@@ -1738,21 +1797,12 @@ function formatApproxUsd(n) {
|
|
|
1738
1797
|
return "~$" + Math.round(n).toLocaleString("en-US");
|
|
1739
1798
|
}
|
|
1740
1799
|
|
|
1741
|
-
// src/render/
|
|
1800
|
+
// src/render/model-display.ts
|
|
1742
1801
|
init_esm_shims();
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
if (values.length === 0) return "";
|
|
1748
|
-
const min = Math.min(...values);
|
|
1749
|
-
const max = Math.max(...values);
|
|
1750
|
-
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("");
|
|
1802
|
+
function displayModel(model) {
|
|
1803
|
+
const m = model.match(/^claude-(opus|sonnet|haiku)-(\d+)-(\d+)(?:-\d+)?$/i);
|
|
1804
|
+
if (m) return `${m[1].toLowerCase()}-${m[2]}.${m[3]}`;
|
|
1805
|
+
return model.startsWith("claude-") ? model.slice("claude-".length) : model;
|
|
1756
1806
|
}
|
|
1757
1807
|
|
|
1758
1808
|
// src/render/local-preview.ts
|
|
@@ -1761,37 +1811,62 @@ function renderLocalPreview(summary, style) {
|
|
|
1761
1811
|
const g = glyphs(style.ascii);
|
|
1762
1812
|
const lines = [];
|
|
1763
1813
|
lines.push(
|
|
1764
|
-
c.
|
|
1814
|
+
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
1815
|
);
|
|
1766
1816
|
lines.push("");
|
|
1767
|
-
lines.push(c.
|
|
1768
|
-
const headers = ["date", "tokens", "~$ est"];
|
|
1769
|
-
const aligns = ["left", "right", "right"];
|
|
1817
|
+
lines.push(c.coral("\u{1FA99} tokenboard") + c.dim(" \xB7 your usage by day"));
|
|
1818
|
+
const headers = ["date", "model", "tokens", "~$ est"];
|
|
1819
|
+
const aligns = ["left", "left", "right", "right"];
|
|
1770
1820
|
const bodyRows = summary.perDay.map((d) => [
|
|
1771
1821
|
d.date,
|
|
1822
|
+
displayModel(d.model),
|
|
1772
1823
|
humanizeTokens(d.tokens),
|
|
1773
1824
|
formatApproxUsd(d.costUsd)
|
|
1774
1825
|
]);
|
|
1775
|
-
const
|
|
1826
|
+
const totalModel = summary.perModel[0] ? displayModel(summary.perModel[0].model) : "";
|
|
1827
|
+
const totalRow = ["TOTAL", totalModel, humanizeTokens(summary.totalTokens), formatApproxUsd(summary.totalCostUsd)];
|
|
1776
1828
|
const allRows = [headers, ...bodyRows, totalRow];
|
|
1777
1829
|
const colWidths = headers.map(
|
|
1778
1830
|
(_, col) => Math.max(...allRows.map((r) => [...r[col]].length), 1)
|
|
1779
1831
|
);
|
|
1780
1832
|
const cellAlign = (i) => aligns[i] ?? "left";
|
|
1781
1833
|
const width = (i) => colWidths[i] ?? 1;
|
|
1782
|
-
const renderRow = (cells
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
const
|
|
1791
|
-
|
|
1792
|
-
|
|
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
|
|
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.dim(p);
|
|
1854
|
+
if (col === 2) return c.accentByLevel(p, norm(d.tokens));
|
|
1855
|
+
if (col === 3) return c.dim(p);
|
|
1856
|
+
return p;
|
|
1857
|
+
})
|
|
1858
|
+
);
|
|
1859
|
+
});
|
|
1860
|
+
lines.push(dimRule("mid"));
|
|
1861
|
+
lines.push(
|
|
1862
|
+
renderRow(totalRow, (p, col) => {
|
|
1863
|
+
if (col === 0) return c.dim(c.bold(p));
|
|
1864
|
+
if (col === 1) return c.coral(p);
|
|
1865
|
+
if (col === 2) return c.bold(c.coral(p));
|
|
1866
|
+
return c.coral(p);
|
|
1867
|
+
})
|
|
1793
1868
|
);
|
|
1794
|
-
|
|
1869
|
+
lines.push(dimRule("bottom"));
|
|
1795
1870
|
lines.push(
|
|
1796
1871
|
c.dim("approx $ is a local estimate from a bundled LiteLLM snapshot \u2014 the server is authoritative")
|
|
1797
1872
|
);
|
|
@@ -2442,7 +2517,10 @@ async function runPreview(args) {
|
|
|
2442
2517
|
noColorEnv: process.env["NO_COLOR"] !== void 0,
|
|
2443
2518
|
noColorFlag: args.noColor,
|
|
2444
2519
|
asciiFlag: args.ascii,
|
|
2445
|
-
columns: process.stdout.columns
|
|
2520
|
+
columns: process.stdout.columns,
|
|
2521
|
+
colorterm: process.env["COLORTERM"],
|
|
2522
|
+
term: process.env["TERM"],
|
|
2523
|
+
forceColor: process.env["FORCE_COLOR"]
|
|
2446
2524
|
});
|
|
2447
2525
|
process.stdout.write(renderLocalPreview(summary, style) + "\n");
|
|
2448
2526
|
await offerClaim(style);
|