claude-code-cost 0.17.0 → 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 +81 -31
- package/public/style.css +57 -10
- package/server.js +20 -5
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
|
|
|
@@ -705,27 +729,36 @@ function ampm(h) {
|
|
|
705
729
|
}
|
|
706
730
|
|
|
707
731
|
function buildHeatmap(hm, days, today) {
|
|
708
|
-
|
|
732
|
+
// Post-midnight columns sit at each row's tail and read from the next calendar day — the
|
|
733
|
+
// night belongs to the evening it continues, not the morning it precedes. Each row's 24
|
|
734
|
+
// displayed costs are precomputed here (the last row's tail is the future: all zeros).
|
|
735
|
+
const rowCosts = hm.map((row, d) => [
|
|
736
|
+
...row.slice(HEATMAP_START_HOUR),
|
|
737
|
+
...(hm[d + 1] ? hm[d + 1].slice(0, HEATMAP_START_HOUR) : new Array(HEATMAP_START_HOUR).fill(0)),
|
|
738
|
+
]);
|
|
739
|
+
const max = rowCosts.reduce((m, row) => Math.max(m, ...row), 0);
|
|
709
740
|
if (max === 0) return '<div class="empty-state"><div>No activity in this range</div></div>';
|
|
741
|
+
const labels = days.map(heatmapDayLabel);
|
|
710
742
|
const hourAt = (col) => (col + HEATMAP_START_HOUR) % 24;
|
|
711
743
|
const hours = Array.from(
|
|
712
744
|
{ length: 24 },
|
|
713
745
|
(_, col) => `<span class="hm-hour">${hourAt(col) % 3 === 0 ? ampm(hourAt(col)) : ''}</span>`,
|
|
714
746
|
).join('');
|
|
715
747
|
const rows = hm
|
|
716
|
-
.map((
|
|
717
|
-
const label =
|
|
748
|
+
.map((_, d) => {
|
|
749
|
+
const label = labels[d];
|
|
718
750
|
return `
|
|
719
751
|
<div class="hm-row${days[d] === today ? ' hm-today' : ''}">
|
|
720
752
|
<span class="hm-day">${label}</span>
|
|
721
|
-
${
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
<span class="hm-cell" data-hm="${label}|${h}|${cost}">
|
|
753
|
+
${rowCosts[d]
|
|
754
|
+
.map((cost, col) => {
|
|
755
|
+
const h = hourAt(col);
|
|
756
|
+
return `
|
|
757
|
+
<span class="hm-cell" data-hm="${h < HEATMAP_START_HOUR ? (labels[d + 1] ?? label) : label}|${h}|${cost}">
|
|
726
758
|
<i style="opacity:${cost > 0 ? Math.max(0.12, cost / max).toFixed(2) : 0}"></i>
|
|
727
759
|
</span>`;
|
|
728
|
-
|
|
760
|
+
})
|
|
761
|
+
.join('')}
|
|
729
762
|
</div>`;
|
|
730
763
|
})
|
|
731
764
|
.join('');
|
|
@@ -759,13 +792,13 @@ function initHeatmapTooltip() {
|
|
|
759
792
|
|
|
760
793
|
// Hour-only span (e.g. "15:00–20:00") so the card makes it obvious a fresh block just opened.
|
|
761
794
|
function blockHours(b) {
|
|
762
|
-
const
|
|
763
|
-
return `${
|
|
795
|
+
const opts = { hour: '2-digit', minute: '2-digit' };
|
|
796
|
+
return `${localTime(b.start, opts)} – ${localTime(b.end, opts)}`;
|
|
764
797
|
}
|
|
765
798
|
|
|
766
799
|
function blockSpanLabel(b) {
|
|
767
800
|
const opts = { month: 'short', day: 'numeric', hour: 'numeric' };
|
|
768
|
-
return `${new Date(b.start).toLocaleString(undefined, opts)} – ${
|
|
801
|
+
return `${stripNarrowSpace(new Date(b.start).toLocaleString(undefined, opts))} – ${localTime(b.end, { hour: 'numeric' })}`;
|
|
769
802
|
}
|
|
770
803
|
|
|
771
804
|
// Classifies the active block's projection: against the live usage limit when the statusline
|
|
@@ -778,7 +811,7 @@ function burnPace(ab, blocks) {
|
|
|
778
811
|
if (ab.usedPct != null) {
|
|
779
812
|
const projPct = (ab.usedPct / elapsedMin) * blockMin;
|
|
780
813
|
const cls = projPct >= 100 ? 'hot' : projPct >= 80 ? 'warn' : 'ok';
|
|
781
|
-
return { cls,
|
|
814
|
+
return { cls, pct: Math.round(Math.min(projPct, 999)) };
|
|
782
815
|
}
|
|
783
816
|
const past = blocks
|
|
784
817
|
.filter((b) => !b.active && b.cost > 0)
|
|
@@ -809,6 +842,8 @@ function renderInsights() {
|
|
|
809
842
|
const sub = d.subagents;
|
|
810
843
|
const agentTotal = sub.mainCost + sub.subagentCost;
|
|
811
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;
|
|
812
847
|
const showWeekly = d.weekly.length >= 3;
|
|
813
848
|
|
|
814
849
|
el.innerHTML = `
|
|
@@ -819,27 +854,31 @@ function renderInsights() {
|
|
|
819
854
|
<div class="stat-card">
|
|
820
855
|
<div class="card-label">Active 5h Block</div>
|
|
821
856
|
<div class="card-value cost">${ab ? formatCost(ab.cost) : '—'}</div>
|
|
822
|
-
|
|
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>
|
|
823
859
|
</div>
|
|
824
860
|
<div class="stat-card">
|
|
825
861
|
<div class="card-label">Burn Rate</div>
|
|
826
862
|
<div class="card-value ${esc(pace ? `pace-${pace.cls}` : '')}">${ab ? `${formatCost(ab.burn.costPerHour)}/h` : '—'}</div>
|
|
827
|
-
|
|
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>
|
|
828
865
|
</div>
|
|
829
866
|
<div class="stat-card">
|
|
830
867
|
<div class="card-label">Monthly Run-Rate</div>
|
|
831
868
|
<div class="card-value cost">${formatCost(d.runRate.projectedMonthly)}</div>
|
|
832
|
-
<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>
|
|
833
870
|
</div>
|
|
834
871
|
<div class="stat-card">
|
|
835
872
|
<div class="card-label">Cache Savings</div>
|
|
836
873
|
<div class="card-value cost">${formatCost(d.cacheSavings)}</div>
|
|
837
|
-
|
|
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>
|
|
838
876
|
</div>
|
|
839
877
|
<div class="stat-card">
|
|
840
878
|
<div class="card-label">Subagent Share</div>
|
|
841
879
|
<div class="card-value">${subPct}%</div>
|
|
842
|
-
|
|
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>
|
|
843
882
|
</div>
|
|
844
883
|
</div>
|
|
845
884
|
|
|
@@ -1124,7 +1163,7 @@ function buildMessageRow(m) {
|
|
|
1124
1163
|
: `<span class="model-badge">${esc(shortModel(m.model))}</span>${toolTags ? ` ${toolTags}` : ''}`;
|
|
1125
1164
|
return `<tr>
|
|
1126
1165
|
<td class="muted">${m.index}</td>
|
|
1127
|
-
<td class="muted">${
|
|
1166
|
+
<td class="muted">${localTime(m.timestamp)}</td>
|
|
1128
1167
|
<td>${modelCol}</td>
|
|
1129
1168
|
<td>${formatTokens(m.inputTokens)}</td>
|
|
1130
1169
|
<td>${formatTokens(m.outputTokens)}</td>
|
|
@@ -1145,6 +1184,9 @@ function getChartColors() {
|
|
|
1145
1184
|
accent: style.getPropertyValue('--accent').trim() || '#e86f33',
|
|
1146
1185
|
chartFill: style.getPropertyValue('--chart-fill').trim() || 'rgba(232,111,51,0.6)',
|
|
1147
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",
|
|
1148
1190
|
border: style.getPropertyValue('--border').trim() || '#363840',
|
|
1149
1191
|
bg: style.getPropertyValue('--bg-elevated').trim() || '#1e2025',
|
|
1150
1192
|
chart1: style.getPropertyValue('--chart-1').trim() || '#e86f33',
|
|
@@ -1177,19 +1219,29 @@ function messageTooltipTitle(messages, items) {
|
|
|
1177
1219
|
return `#${m.index}${m._subagent ? ` · ${m._subagent.agentType}` : ''}`;
|
|
1178
1220
|
}
|
|
1179
1221
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1222
|
+
// Takes the palette the caller already read, so a chart costs one getComputedStyle, not two.
|
|
1223
|
+
function chartDefaults(c = getChartColors()) {
|
|
1182
1224
|
return {
|
|
1183
1225
|
responsive: true,
|
|
1184
1226
|
maintainAspectRatio: false,
|
|
1185
1227
|
plugins: {
|
|
1186
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.
|
|
1187
1231
|
tooltip: {
|
|
1188
1232
|
backgroundColor: c.bg,
|
|
1189
|
-
titleColor: c.
|
|
1190
|
-
bodyColor: c.
|
|
1233
|
+
titleColor: c.textMuted,
|
|
1234
|
+
bodyColor: c.textPrimary,
|
|
1191
1235
|
borderColor: c.border,
|
|
1192
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,
|
|
1193
1245
|
},
|
|
1194
1246
|
},
|
|
1195
1247
|
scales: {
|
|
@@ -1308,10 +1360,9 @@ function renderCostChart(series, canvasId = 'costChart', chartKey = 'cost', dist
|
|
|
1308
1360
|
options: {
|
|
1309
1361
|
...defaults,
|
|
1310
1362
|
interaction: { mode: 'nearest', intersect: true },
|
|
1311
|
-
events: [],
|
|
1312
1363
|
plugins: {
|
|
1313
|
-
...withTooltip(defaults, { label: (ctx) => usd(ctx.parsed.y) }),
|
|
1314
|
-
//
|
|
1364
|
+
...withTooltip(defaults, { label: (ctx) => `${ctx.dataset.label} ${usd(ctx.parsed.y)}` }),
|
|
1365
|
+
// The legend still carries segment names for the hours nobody hovers.
|
|
1315
1366
|
legend: {
|
|
1316
1367
|
display: models.length > 1,
|
|
1317
1368
|
position: 'bottom',
|
|
@@ -1359,7 +1410,6 @@ function renderModelChart(models, canvasId = 'modelChart', chartKey = 'model') {
|
|
|
1359
1410
|
...defaults,
|
|
1360
1411
|
indexAxis: 'y',
|
|
1361
1412
|
interaction: { mode: 'nearest', intersect: true },
|
|
1362
|
-
events: [],
|
|
1363
1413
|
plugins: withTooltip(defaults, {
|
|
1364
1414
|
label: (ctx) => `${usd(ctx.parsed.x)} (${formatPct(ctx.parsed.x, total)}%)`,
|
|
1365
1415
|
}),
|
|
@@ -1471,7 +1521,7 @@ function renderTokenBreakdownChart(messages) {
|
|
|
1471
1521
|
position: 'bottom',
|
|
1472
1522
|
labels: {
|
|
1473
1523
|
color: c.text,
|
|
1474
|
-
font: { size: 10, family:
|
|
1524
|
+
font: { size: 10, family: c.mono },
|
|
1475
1525
|
padding: 8,
|
|
1476
1526
|
boxWidth: 12,
|
|
1477
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 */
|
package/server.js
CHANGED
|
@@ -631,6 +631,8 @@ function resolveWindow(range, now = new Date()) {
|
|
|
631
631
|
};
|
|
632
632
|
}
|
|
633
633
|
|
|
634
|
+
const byTimestamp = (a, b) => a.timestamp.localeCompare(b.timestamp);
|
|
635
|
+
|
|
634
636
|
// Two-sided when the window has an end, so a window that stops in the past excludes later
|
|
635
637
|
// messages. A null bound means open in that direction.
|
|
636
638
|
function filterWindow(messages, fromStr, toStr) {
|
|
@@ -924,7 +926,7 @@ async function getSessionDetailData(sessionId) {
|
|
|
924
926
|
if (!session) continue;
|
|
925
927
|
|
|
926
928
|
// Sort messages by timestamp
|
|
927
|
-
session.messages.sort(
|
|
929
|
+
session.messages.sort(byTimestamp);
|
|
928
930
|
|
|
929
931
|
// Add cumulative cost
|
|
930
932
|
let cumulative = 0;
|
|
@@ -1082,9 +1084,22 @@ async function getInsightsData(range, projectFilter) {
|
|
|
1082
1084
|
if (!hmInAll) hmParts.push(filterWindow(session.messages, hmStartStr, w.endStr));
|
|
1083
1085
|
}
|
|
1084
1086
|
}
|
|
1085
|
-
const all = allParts.flat().sort(
|
|
1087
|
+
const all = allParts.flat().sort(byTimestamp);
|
|
1086
1088
|
const hmMsgs = hmInAll ? all.filter((m) => m.timestamp >= hmStartStr) : hmParts.flat();
|
|
1087
1089
|
|
|
1090
|
+
// The live 5h window can open before the selected range starts (a Today filter after midnight
|
|
1091
|
+
// cuts a block that opened the evening before), so block stats are computed over the block's
|
|
1092
|
+
// own span. A live block always starts within the last 5h, inside the heatmap window, so its
|
|
1093
|
+
// messages are a subset of hmMsgs — no extra scan needed.
|
|
1094
|
+
const limits = w.hasToday ? readRateLimits(w.now) : null;
|
|
1095
|
+
const blockStart = limits ? new Date(limits.resetsAtMs - BLOCK_MS) : null;
|
|
1096
|
+
const blockInAll = !blockStart || w.cutoff === null || w.cutoff <= blockStart;
|
|
1097
|
+
let blockMsgs = all;
|
|
1098
|
+
if (!blockInAll) {
|
|
1099
|
+
const fromStr = blockStart.toISOString();
|
|
1100
|
+
blockMsgs = hmMsgs.filter((m) => m.timestamp >= fromStr).sort(byTimestamp);
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1088
1103
|
const sum = summarizeMessages(all);
|
|
1089
1104
|
const tokens = { input: sum.inputTokens, output: sum.outputTokens, cacheCreation: sum.cacheCreationTokens, cacheRead: sum.cacheReadTokens };
|
|
1090
1105
|
let cacheSavings = 0;
|
|
@@ -1136,9 +1151,9 @@ async function getInsightsData(range, projectFilter) {
|
|
|
1136
1151
|
if (idx >= 0 && idx < HEATMAP_DAYS) heatmap[idx][d.getHours()] += m.cost;
|
|
1137
1152
|
}
|
|
1138
1153
|
|
|
1139
|
-
|
|
1140
|
-
//
|
|
1141
|
-
const blocks = computeBlocks(
|
|
1154
|
+
// A window ending in the past has no "current" block — limits are only read when the window
|
|
1155
|
+
// reaches today, so the live block is never synthesized for a historical range.
|
|
1156
|
+
const blocks = computeBlocks(blockMsgs, w.now, limits?.resetsAtMs || null);
|
|
1142
1157
|
const activeBlk = blocks.find((b) => b.active);
|
|
1143
1158
|
if (activeBlk) activeBlk.usedPct = limits?.usedPct ?? null;
|
|
1144
1159
|
|