claude-code-cost 0.17.0 → 0.17.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 +18 -9
- package/server.js +20 -5
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -705,27 +705,36 @@ function ampm(h) {
|
|
|
705
705
|
}
|
|
706
706
|
|
|
707
707
|
function buildHeatmap(hm, days, today) {
|
|
708
|
-
|
|
708
|
+
// Post-midnight columns sit at each row's tail and read from the next calendar day — the
|
|
709
|
+
// night belongs to the evening it continues, not the morning it precedes. Each row's 24
|
|
710
|
+
// displayed costs are precomputed here (the last row's tail is the future: all zeros).
|
|
711
|
+
const rowCosts = hm.map((row, d) => [
|
|
712
|
+
...row.slice(HEATMAP_START_HOUR),
|
|
713
|
+
...(hm[d + 1] ? hm[d + 1].slice(0, HEATMAP_START_HOUR) : new Array(HEATMAP_START_HOUR).fill(0)),
|
|
714
|
+
]);
|
|
715
|
+
const max = rowCosts.reduce((m, row) => Math.max(m, ...row), 0);
|
|
709
716
|
if (max === 0) return '<div class="empty-state"><div>No activity in this range</div></div>';
|
|
717
|
+
const labels = days.map(heatmapDayLabel);
|
|
710
718
|
const hourAt = (col) => (col + HEATMAP_START_HOUR) % 24;
|
|
711
719
|
const hours = Array.from(
|
|
712
720
|
{ length: 24 },
|
|
713
721
|
(_, col) => `<span class="hm-hour">${hourAt(col) % 3 === 0 ? ampm(hourAt(col)) : ''}</span>`,
|
|
714
722
|
).join('');
|
|
715
723
|
const rows = hm
|
|
716
|
-
.map((
|
|
717
|
-
const label =
|
|
724
|
+
.map((_, d) => {
|
|
725
|
+
const label = labels[d];
|
|
718
726
|
return `
|
|
719
727
|
<div class="hm-row${days[d] === today ? ' hm-today' : ''}">
|
|
720
728
|
<span class="hm-day">${label}</span>
|
|
721
|
-
${
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
<span class="hm-cell" data-hm="${label}|${h}|${cost}">
|
|
729
|
+
${rowCosts[d]
|
|
730
|
+
.map((cost, col) => {
|
|
731
|
+
const h = hourAt(col);
|
|
732
|
+
return `
|
|
733
|
+
<span class="hm-cell" data-hm="${h < HEATMAP_START_HOUR ? (labels[d + 1] ?? label) : label}|${h}|${cost}">
|
|
726
734
|
<i style="opacity:${cost > 0 ? Math.max(0.12, cost / max).toFixed(2) : 0}"></i>
|
|
727
735
|
</span>`;
|
|
728
|
-
|
|
736
|
+
})
|
|
737
|
+
.join('')}
|
|
729
738
|
</div>`;
|
|
730
739
|
})
|
|
731
740
|
.join('');
|
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
|
|