claude-code-cost 0.17.1 → 0.18.1
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/package.json +1 -1
- package/public/app.js +63 -22
- package/public/style.css +57 -10
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -74,6 +74,27 @@ function formatPct(part, total) {
|
|
|
74
74
|
return total > 0 ? ((part / total) * 100).toFixed(1) : '0.0';
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// Intl puts U+202F before AM/PM, which reads as a stray gap in the mono font. Every
|
|
78
|
+
// locale format that can emit an hour goes through here so the strip cannot drift.
|
|
79
|
+
function stripNarrowSpace(str) {
|
|
80
|
+
return str.replace(/\u202f/g, ' ');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function localTime(iso, opts) {
|
|
84
|
+
return stripNarrowSpace(new Date(iso).toLocaleTimeString(undefined, opts));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// One meter for every share/progress card. Owns the clamp and the aria contract so a new
|
|
88
|
+
// call site cannot invent a sixth clamping idiom.
|
|
89
|
+
function meter(pct, { label = '', cls = '', ariaLabel = '' } = {}) {
|
|
90
|
+
const width = Math.min(100, Math.max(0, Number(pct) || 0)).toFixed(1);
|
|
91
|
+
const klass = esc(cls ? `meter ${cls}` : 'meter');
|
|
92
|
+
return `<div class="${klass}" role="img" aria-label="${esc(ariaLabel)}">
|
|
93
|
+
<div class="meter-track"><i style="width:${width}%"></i></div>
|
|
94
|
+
${label ? `<span class="meter-value">${esc(label)}</span>` : ''}
|
|
95
|
+
</div>`;
|
|
96
|
+
}
|
|
97
|
+
|
|
77
98
|
function formatDuration(minutes) {
|
|
78
99
|
if (!minutes || minutes < 1) return '<1m';
|
|
79
100
|
if (minutes < 60) return `${minutes}m`;
|
|
@@ -99,7 +120,7 @@ function timeAgo(ts) {
|
|
|
99
120
|
// time with no zone suffix.
|
|
100
121
|
function bucketLabel(key, bucket) {
|
|
101
122
|
if (bucket === 'hour') {
|
|
102
|
-
return
|
|
123
|
+
return localTime(`${key}:00:00`, { hour: 'numeric' });
|
|
103
124
|
}
|
|
104
125
|
return new Date(`${key}T00:00:00`).toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
|
|
105
126
|
}
|
|
@@ -576,6 +597,8 @@ function renderOverview() {
|
|
|
576
597
|
|
|
577
598
|
const costSeries = overviewData.costSeries;
|
|
578
599
|
const models = overviewData.modelDistribution || [];
|
|
600
|
+
// null, not 0, when nothing cacheable ran — an empty range should show no meter at all.
|
|
601
|
+
const cachePct = s.totalCacheRead + s.totalCacheCreation > 0 ? s.cacheEfficiency * 100 : null;
|
|
579
602
|
|
|
580
603
|
// Return before any chart call so no canvas is touched — there are none in this markup.
|
|
581
604
|
if (scopeProject && s.totalSessions === 0) {
|
|
@@ -627,8 +650,9 @@ function renderOverview() {
|
|
|
627
650
|
</div>
|
|
628
651
|
<div class="stat-card">
|
|
629
652
|
<div class="card-label">Cache Efficiency</div>
|
|
630
|
-
<div class="card-value">${
|
|
631
|
-
|
|
653
|
+
<div class="card-value">${cachePct == null ? '0.0' : cachePct.toFixed(1)}%</div>
|
|
654
|
+
${cachePct == null ? '' : meter(cachePct, { ariaLabel: `${cachePct.toFixed(1)}% of all input tokens were served from cache` })}
|
|
655
|
+
<div class="card-sub">Read: <strong>${formatTokens(s.totalCacheRead)}</strong> / Created: ${formatTokens(s.totalCacheCreation)}</div>
|
|
632
656
|
</div>
|
|
633
657
|
</div>
|
|
634
658
|
|
|
@@ -768,13 +792,13 @@ function initHeatmapTooltip() {
|
|
|
768
792
|
|
|
769
793
|
// Hour-only span (e.g. "15:00–20:00") so the card makes it obvious a fresh block just opened.
|
|
770
794
|
function blockHours(b) {
|
|
771
|
-
const
|
|
772
|
-
return `${
|
|
795
|
+
const opts = { hour: '2-digit', minute: '2-digit' };
|
|
796
|
+
return `${localTime(b.start, opts)} – ${localTime(b.end, opts)}`;
|
|
773
797
|
}
|
|
774
798
|
|
|
775
799
|
function blockSpanLabel(b) {
|
|
776
800
|
const opts = { month: 'short', day: 'numeric', hour: 'numeric' };
|
|
777
|
-
return `${new Date(b.start).toLocaleString(undefined, opts)} – ${
|
|
801
|
+
return `${stripNarrowSpace(new Date(b.start).toLocaleString(undefined, opts))} – ${localTime(b.end, { hour: 'numeric' })}`;
|
|
778
802
|
}
|
|
779
803
|
|
|
780
804
|
// Classifies the active block's projection: against the live usage limit when the statusline
|
|
@@ -787,7 +811,7 @@ function burnPace(ab, blocks) {
|
|
|
787
811
|
if (ab.usedPct != null) {
|
|
788
812
|
const projPct = (ab.usedPct / elapsedMin) * blockMin;
|
|
789
813
|
const cls = projPct >= 100 ? 'hot' : projPct >= 80 ? 'warn' : 'ok';
|
|
790
|
-
return { cls,
|
|
814
|
+
return { cls, pct: Math.round(Math.min(projPct, 999)) };
|
|
791
815
|
}
|
|
792
816
|
const past = blocks
|
|
793
817
|
.filter((b) => !b.active && b.cost > 0)
|
|
@@ -818,6 +842,8 @@ function renderInsights() {
|
|
|
818
842
|
const sub = d.subagents;
|
|
819
843
|
const agentTotal = sub.mainCost + sub.subagentCost;
|
|
820
844
|
const subPct = formatPct(sub.subagentCost, agentTotal);
|
|
845
|
+
const cacheable = d.tokens.cacheRead + d.tokens.cacheCreation;
|
|
846
|
+
const cacheHitPct = cacheable > 0 ? Math.round((d.tokens.cacheRead / cacheable) * 100) : null;
|
|
821
847
|
const showWeekly = d.weekly.length >= 3;
|
|
822
848
|
|
|
823
849
|
el.innerHTML = `
|
|
@@ -828,27 +854,31 @@ function renderInsights() {
|
|
|
828
854
|
<div class="stat-card">
|
|
829
855
|
<div class="card-label">Active 5h Block</div>
|
|
830
856
|
<div class="card-value cost">${ab ? formatCost(ab.cost) : '—'}</div>
|
|
831
|
-
|
|
857
|
+
${ab?.usedPct == null ? '' : meter(ab.usedPct, { label: `${Math.round(ab.usedPct)}%`, ariaLabel: `${Math.round(ab.usedPct)}% of the 5h block used` })}
|
|
858
|
+
<div class="card-sub">${ab ? `${blockHours(ab)} · <strong>${formatDuration(ab.burn.remainingMin)} left</strong>` : 'no live window data'}</div>
|
|
832
859
|
</div>
|
|
833
860
|
<div class="stat-card">
|
|
834
861
|
<div class="card-label">Burn Rate</div>
|
|
835
862
|
<div class="card-value ${esc(pace ? `pace-${pace.cls}` : '')}">${ab ? `${formatCost(ab.burn.costPerHour)}/h` : '—'}</div>
|
|
836
|
-
|
|
863
|
+
${pace?.pct == null ? '' : meter(pace.pct, { label: `${pace.pct}%`, cls: `pace-${pace.cls}`, ariaLabel: `on pace for ${pace.pct}% of the usage limit` })}
|
|
864
|
+
<div class="card-sub">${ab ? `${formatTokens(Math.round(ab.burn.tokensPerMin))} tok/min · proj. <strong>${formatCost(ab.burn.projectedCost)}</strong> by block end${pace?.note ? ` · ${pace.note}` : ''}` : 'no active block'}</div>
|
|
837
865
|
</div>
|
|
838
866
|
<div class="stat-card">
|
|
839
867
|
<div class="card-label">Monthly Run-Rate</div>
|
|
840
868
|
<div class="card-value cost">${formatCost(d.runRate.projectedMonthly)}</div>
|
|
841
|
-
<div class="card-sub">${formatCost(d.runRate.dailyAvg)}/day over ${d.runRate.days} ${d.runRate.days === 1 ? 'day' : 'days'}</div>
|
|
869
|
+
<div class="card-sub"><strong>${formatCost(d.runRate.dailyAvg)}/day</strong> over ${d.runRate.days} ${d.runRate.days === 1 ? 'day' : 'days'}</div>
|
|
842
870
|
</div>
|
|
843
871
|
<div class="stat-card">
|
|
844
872
|
<div class="card-label">Cache Savings</div>
|
|
845
873
|
<div class="card-value cost">${formatCost(d.cacheSavings)}</div>
|
|
846
|
-
|
|
874
|
+
${cacheHitPct == null ? '' : meter(cacheHitPct, { label: `${cacheHitPct}% hit`, ariaLabel: `${cacheHitPct}% of cacheable input was served from cache, not re-sent` })}
|
|
875
|
+
<div class="card-sub">vs. uncached input · <strong>${formatTokens(d.tokens.cacheRead)}</strong> reads</div>
|
|
847
876
|
</div>
|
|
848
877
|
<div class="stat-card">
|
|
849
878
|
<div class="card-label">Subagent Share</div>
|
|
850
879
|
<div class="card-value">${subPct}%</div>
|
|
851
|
-
|
|
880
|
+
${agentTotal > 0 ? meter(subPct, { ariaLabel: `subagents are ${subPct}% of ${formatCost(agentTotal)} in agent cost` }) : ''}
|
|
881
|
+
<div class="card-sub"><strong>${formatCost(sub.subagentCost)}</strong> of ${formatCost(agentTotal)}</div>
|
|
852
882
|
</div>
|
|
853
883
|
</div>
|
|
854
884
|
|
|
@@ -1133,7 +1163,7 @@ function buildMessageRow(m) {
|
|
|
1133
1163
|
: `<span class="model-badge">${esc(shortModel(m.model))}</span>${toolTags ? ` ${toolTags}` : ''}`;
|
|
1134
1164
|
return `<tr>
|
|
1135
1165
|
<td class="muted">${m.index}</td>
|
|
1136
|
-
<td class="muted">${
|
|
1166
|
+
<td class="muted">${localTime(m.timestamp)}</td>
|
|
1137
1167
|
<td>${modelCol}</td>
|
|
1138
1168
|
<td>${formatTokens(m.inputTokens)}</td>
|
|
1139
1169
|
<td>${formatTokens(m.outputTokens)}</td>
|
|
@@ -1154,6 +1184,9 @@ function getChartColors() {
|
|
|
1154
1184
|
accent: style.getPropertyValue('--accent').trim() || '#e86f33',
|
|
1155
1185
|
chartFill: style.getPropertyValue('--chart-fill').trim() || 'rgba(232,111,51,0.6)',
|
|
1156
1186
|
text: style.getPropertyValue('--text-secondary').trim() || '#c2c4c9',
|
|
1187
|
+
textPrimary: style.getPropertyValue('--text-primary').trim() || '#f0f1f3',
|
|
1188
|
+
textMuted: style.getPropertyValue('--text-muted').trim() || '#7d808a',
|
|
1189
|
+
mono: style.getPropertyValue('--mono').trim() || "'IBM Plex Mono', monospace",
|
|
1157
1190
|
border: style.getPropertyValue('--border').trim() || '#363840',
|
|
1158
1191
|
bg: style.getPropertyValue('--bg-elevated').trim() || '#1e2025',
|
|
1159
1192
|
chart1: style.getPropertyValue('--chart-1').trim() || '#e86f33',
|
|
@@ -1186,19 +1219,29 @@ function messageTooltipTitle(messages, items) {
|
|
|
1186
1219
|
return `#${m.index}${m._subagent ? ` · ${m._subagent.agentType}` : ''}`;
|
|
1187
1220
|
}
|
|
1188
1221
|
|
|
1189
|
-
|
|
1190
|
-
|
|
1222
|
+
// Takes the palette the caller already read, so a chart costs one getComputedStyle, not two.
|
|
1223
|
+
function chartDefaults(c = getChartColors()) {
|
|
1191
1224
|
return {
|
|
1192
1225
|
responsive: true,
|
|
1193
1226
|
maintainAspectRatio: false,
|
|
1194
1227
|
plugins: {
|
|
1195
1228
|
legend: { display: false },
|
|
1229
|
+
// Mirrors .hm-tip so a chart hover and a heatmap hover read as the same tooltip:
|
|
1230
|
+
// elevated bg, muted label above, primary value below, mono throughout.
|
|
1196
1231
|
tooltip: {
|
|
1197
1232
|
backgroundColor: c.bg,
|
|
1198
|
-
titleColor: c.
|
|
1199
|
-
bodyColor: c.
|
|
1233
|
+
titleColor: c.textMuted,
|
|
1234
|
+
bodyColor: c.textPrimary,
|
|
1200
1235
|
borderColor: c.border,
|
|
1201
1236
|
borderWidth: 1,
|
|
1237
|
+
cornerRadius: 4,
|
|
1238
|
+
padding: { top: 5, bottom: 5, left: 8, right: 8 },
|
|
1239
|
+
titleFont: { family: c.mono, size: 10, weight: 'normal' },
|
|
1240
|
+
bodyFont: { family: c.mono, size: 13, weight: '600' },
|
|
1241
|
+
titleMarginBottom: 2,
|
|
1242
|
+
boxWidth: 8,
|
|
1243
|
+
boxHeight: 8,
|
|
1244
|
+
boxPadding: 4,
|
|
1202
1245
|
},
|
|
1203
1246
|
},
|
|
1204
1247
|
scales: {
|
|
@@ -1317,10 +1360,9 @@ function renderCostChart(series, canvasId = 'costChart', chartKey = 'cost', dist
|
|
|
1317
1360
|
options: {
|
|
1318
1361
|
...defaults,
|
|
1319
1362
|
interaction: { mode: 'nearest', intersect: true },
|
|
1320
|
-
events: [],
|
|
1321
1363
|
plugins: {
|
|
1322
|
-
...withTooltip(defaults, { label: (ctx) => usd(ctx.parsed.y) }),
|
|
1323
|
-
//
|
|
1364
|
+
...withTooltip(defaults, { label: (ctx) => `${ctx.dataset.label} ${usd(ctx.parsed.y)}` }),
|
|
1365
|
+
// The legend still carries segment names for the hours nobody hovers.
|
|
1324
1366
|
legend: {
|
|
1325
1367
|
display: models.length > 1,
|
|
1326
1368
|
position: 'bottom',
|
|
@@ -1368,7 +1410,6 @@ function renderModelChart(models, canvasId = 'modelChart', chartKey = 'model') {
|
|
|
1368
1410
|
...defaults,
|
|
1369
1411
|
indexAxis: 'y',
|
|
1370
1412
|
interaction: { mode: 'nearest', intersect: true },
|
|
1371
|
-
events: [],
|
|
1372
1413
|
plugins: withTooltip(defaults, {
|
|
1373
1414
|
label: (ctx) => `${usd(ctx.parsed.x)} (${formatPct(ctx.parsed.x, total)}%)`,
|
|
1374
1415
|
}),
|
|
@@ -1480,7 +1521,7 @@ function renderTokenBreakdownChart(messages) {
|
|
|
1480
1521
|
position: 'bottom',
|
|
1481
1522
|
labels: {
|
|
1482
1523
|
color: c.text,
|
|
1483
|
-
font: { size: 10, family:
|
|
1524
|
+
font: { size: 10, family: c.mono },
|
|
1484
1525
|
padding: 8,
|
|
1485
1526
|
boxWidth: 12,
|
|
1486
1527
|
boxHeight: 12,
|
package/public/style.css
CHANGED
|
@@ -618,7 +618,7 @@ body {
|
|
|
618
618
|
}
|
|
619
619
|
|
|
620
620
|
.dashboard-content {
|
|
621
|
-
max-width:
|
|
621
|
+
max-width: 1600px;
|
|
622
622
|
margin: 0 auto;
|
|
623
623
|
}
|
|
624
624
|
|
|
@@ -636,7 +636,7 @@ body {
|
|
|
636
636
|
|
|
637
637
|
.cards-row {
|
|
638
638
|
display: grid;
|
|
639
|
-
grid-template-columns: repeat(auto-fit, minmax(
|
|
639
|
+
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
|
640
640
|
gap: 12px;
|
|
641
641
|
margin-bottom: 20px;
|
|
642
642
|
}
|
|
@@ -678,6 +678,42 @@ body {
|
|
|
678
678
|
margin-top: 4px;
|
|
679
679
|
}
|
|
680
680
|
|
|
681
|
+
.stat-card .card-sub strong {
|
|
682
|
+
color: var(--text-primary);
|
|
683
|
+
font-weight: 600;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
.stat-card .meter {
|
|
687
|
+
display: flex;
|
|
688
|
+
align-items: center;
|
|
689
|
+
gap: 6px;
|
|
690
|
+
margin-top: 8px;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
.stat-card .meter-track {
|
|
694
|
+
flex: 1;
|
|
695
|
+
min-width: 0;
|
|
696
|
+
height: 3px;
|
|
697
|
+
background: var(--meter-dim, var(--accent-dim));
|
|
698
|
+
border-radius: 2px;
|
|
699
|
+
overflow: hidden;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
.stat-card .meter-track > i {
|
|
703
|
+
display: block;
|
|
704
|
+
height: 100%;
|
|
705
|
+
background: var(--meter, var(--accent));
|
|
706
|
+
border-radius: 2px;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
.stat-card .meter-value {
|
|
710
|
+
flex: none;
|
|
711
|
+
font-family: var(--mono);
|
|
712
|
+
font-size: 10px;
|
|
713
|
+
font-weight: 600;
|
|
714
|
+
color: var(--meter, var(--text-primary));
|
|
715
|
+
}
|
|
716
|
+
|
|
681
717
|
/* #endregion */
|
|
682
718
|
|
|
683
719
|
/* #region CHARTS */
|
|
@@ -1248,8 +1284,8 @@ kbd {
|
|
|
1248
1284
|
|
|
1249
1285
|
.hm-cell {
|
|
1250
1286
|
position: relative;
|
|
1251
|
-
aspect-ratio:
|
|
1252
|
-
min-height:
|
|
1287
|
+
aspect-ratio: 2.4;
|
|
1288
|
+
min-height: 10px;
|
|
1253
1289
|
border-radius: 2px;
|
|
1254
1290
|
background: var(--bg-hover);
|
|
1255
1291
|
overflow: hidden;
|
|
@@ -1287,7 +1323,7 @@ kbd {
|
|
|
1287
1323
|
}
|
|
1288
1324
|
|
|
1289
1325
|
.hm-tip b {
|
|
1290
|
-
font-size:
|
|
1326
|
+
font-size: 13px;
|
|
1291
1327
|
color: var(--text-primary);
|
|
1292
1328
|
}
|
|
1293
1329
|
|
|
@@ -1312,14 +1348,25 @@ kbd {
|
|
|
1312
1348
|
background: var(--success-dim);
|
|
1313
1349
|
}
|
|
1314
1350
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1351
|
+
/* One status mapping for every pace-colored element: the modifier sets the tokens,
|
|
1352
|
+
.card-value and .meter both read them. A new pace state costs one line. */
|
|
1353
|
+
.pace-ok {
|
|
1354
|
+
--meter: var(--success);
|
|
1355
|
+
--meter-dim: var(--success-dim);
|
|
1356
|
+
}
|
|
1357
|
+
.pace-warn {
|
|
1358
|
+
--meter: var(--warning);
|
|
1359
|
+
--meter-dim: var(--warning-dim);
|
|
1317
1360
|
}
|
|
1318
|
-
.
|
|
1319
|
-
|
|
1361
|
+
.pace-hot {
|
|
1362
|
+
--meter: var(--error);
|
|
1363
|
+
--meter-dim: var(--error-dim);
|
|
1320
1364
|
}
|
|
1365
|
+
|
|
1366
|
+
.card-value.pace-ok,
|
|
1367
|
+
.card-value.pace-warn,
|
|
1321
1368
|
.card-value.pace-hot {
|
|
1322
|
-
color: var(--
|
|
1369
|
+
color: var(--meter);
|
|
1323
1370
|
}
|
|
1324
1371
|
|
|
1325
1372
|
/* #endregion */
|