claude-code-cost 0.16.1 → 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 +62 -21
- package/public/index.html +1 -0
- package/public/style.css +10 -5
- 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('');
|
|
@@ -819,7 +828,7 @@ function renderInsights() {
|
|
|
819
828
|
<div class="stat-card">
|
|
820
829
|
<div class="card-label">Active 5h Block</div>
|
|
821
830
|
<div class="card-value cost">${ab ? formatCost(ab.cost) : '—'}</div>
|
|
822
|
-
<div class="card-sub">${ab ? `${blockHours(ab)} · ${formatDuration(ab.burn.remainingMin)} left${ab.usedPct != null ? ` · ${ab.usedPct}% used` : ''}` : 'no live window data'}</div>
|
|
831
|
+
<div class="card-sub">${ab ? `${blockHours(ab)} · ${formatDuration(ab.burn.remainingMin)} left${ab.usedPct != null ? ` · ${Math.round(ab.usedPct)}% used` : ''}` : 'no live window data'}</div>
|
|
823
832
|
</div>
|
|
824
833
|
<div class="stat-card">
|
|
825
834
|
<div class="card-label">Burn Rate</div>
|
|
@@ -1087,9 +1096,8 @@ function renderDetail() {
|
|
|
1087
1096
|
</div>`;
|
|
1088
1097
|
|
|
1089
1098
|
requestAnimationFrame(() => {
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
renderTokenBreakdownChart(parentMessages);
|
|
1099
|
+
renderCumulativeChart(d.messages);
|
|
1100
|
+
renderTokenBreakdownChart(d.messages);
|
|
1093
1101
|
});
|
|
1094
1102
|
}
|
|
1095
1103
|
|
|
@@ -1171,6 +1179,13 @@ function hexToRgba(hex, alpha) {
|
|
|
1171
1179
|
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
1172
1180
|
}
|
|
1173
1181
|
|
|
1182
|
+
// Tooltip title for per-message charts: names the subagent when the point is a folded-in agent run.
|
|
1183
|
+
function messageTooltipTitle(messages, items) {
|
|
1184
|
+
const m = messages[items[0]?.dataIndex];
|
|
1185
|
+
if (!m) return '';
|
|
1186
|
+
return `#${m.index}${m._subagent ? ` · ${m._subagent.agentType}` : ''}`;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1174
1189
|
function chartDefaults() {
|
|
1175
1190
|
const c = getChartColors();
|
|
1176
1191
|
return {
|
|
@@ -1376,7 +1391,7 @@ function renderCumulativeChart(messages) {
|
|
|
1376
1391
|
charts.cumulative = new Chart(canvas, {
|
|
1377
1392
|
type: 'line',
|
|
1378
1393
|
data: {
|
|
1379
|
-
labels: messages.map((
|
|
1394
|
+
labels: messages.map((m) => m.index),
|
|
1380
1395
|
datasets: [
|
|
1381
1396
|
{
|
|
1382
1397
|
label: 'Cumulative Cost',
|
|
@@ -1386,13 +1401,16 @@ function renderCumulativeChart(messages) {
|
|
|
1386
1401
|
fill: true,
|
|
1387
1402
|
borderWidth: 2,
|
|
1388
1403
|
pointRadius: messages.length > 50 ? 0 : 3,
|
|
1389
|
-
|
|
1404
|
+
// Subagent points render hollow so they read as folded-in cost, not main-loop turns.
|
|
1405
|
+
pointBackgroundColor: messages.length > 50 ? c.accent : messages.map((m) => (m._subagent ? c.bg : c.accent)),
|
|
1406
|
+
pointBorderColor: c.accent,
|
|
1390
1407
|
tension: 0.2,
|
|
1391
1408
|
},
|
|
1392
1409
|
],
|
|
1393
1410
|
},
|
|
1394
1411
|
options: {
|
|
1395
1412
|
...defaults,
|
|
1413
|
+
plugins: withTooltip(defaults, { title: (items) => messageTooltipTitle(messages, items) }),
|
|
1396
1414
|
scales: {
|
|
1397
1415
|
...defaults.scales,
|
|
1398
1416
|
x: {
|
|
@@ -1416,23 +1434,39 @@ function renderTokenBreakdownChart(messages) {
|
|
|
1416
1434
|
const c = getChartColors();
|
|
1417
1435
|
const defaults = chartDefaults();
|
|
1418
1436
|
|
|
1437
|
+
// Subagent bars render translucent so they read as folded-in usage, not main-loop turns.
|
|
1438
|
+
const barColors = (hex) => {
|
|
1439
|
+
const faded = hexToRgba(hex, 0.45);
|
|
1440
|
+
return messages.map((m) => (m._subagent ? faded : hex));
|
|
1441
|
+
};
|
|
1442
|
+
|
|
1419
1443
|
charts.tokenBreakdown = new Chart(canvas, {
|
|
1420
1444
|
type: 'bar',
|
|
1421
1445
|
data: {
|
|
1422
|
-
labels: messages.map((
|
|
1446
|
+
labels: messages.map((m) => m.index),
|
|
1423
1447
|
datasets: [
|
|
1424
|
-
{
|
|
1425
|
-
|
|
1448
|
+
{
|
|
1449
|
+
label: 'Input',
|
|
1450
|
+
data: messages.map((m) => m.inputTokens),
|
|
1451
|
+
backgroundColor: barColors(c.chart1),
|
|
1452
|
+
borderRadius: 2,
|
|
1453
|
+
},
|
|
1454
|
+
{
|
|
1455
|
+
label: 'Output',
|
|
1456
|
+
data: messages.map((m) => m.outputTokens),
|
|
1457
|
+
backgroundColor: barColors(c.chart2),
|
|
1458
|
+
borderRadius: 2,
|
|
1459
|
+
},
|
|
1426
1460
|
{
|
|
1427
1461
|
label: 'Cache Create',
|
|
1428
1462
|
data: messages.map((m) => m.cacheCreationTokens),
|
|
1429
|
-
backgroundColor: c.chart3,
|
|
1463
|
+
backgroundColor: barColors(c.chart3),
|
|
1430
1464
|
borderRadius: 2,
|
|
1431
1465
|
},
|
|
1432
1466
|
{
|
|
1433
1467
|
label: 'Cache Read',
|
|
1434
1468
|
data: messages.map((m) => m.cacheReadTokens),
|
|
1435
|
-
backgroundColor: c.chart4,
|
|
1469
|
+
backgroundColor: barColors(c.chart4),
|
|
1436
1470
|
borderRadius: 2,
|
|
1437
1471
|
},
|
|
1438
1472
|
],
|
|
@@ -1440,7 +1474,7 @@ function renderTokenBreakdownChart(messages) {
|
|
|
1440
1474
|
options: {
|
|
1441
1475
|
...defaults,
|
|
1442
1476
|
plugins: {
|
|
1443
|
-
...defaults
|
|
1477
|
+
...withTooltip(defaults, { title: (items) => messageTooltipTitle(messages, items) }),
|
|
1444
1478
|
legend: {
|
|
1445
1479
|
display: true,
|
|
1446
1480
|
position: 'bottom',
|
|
@@ -2015,6 +2049,8 @@ async function navigate(view, params) {
|
|
|
2015
2049
|
if (view === 'sessions') {
|
|
2016
2050
|
currentSessionId = null;
|
|
2017
2051
|
}
|
|
2052
|
+
// Remember the last top-level tab so a fresh load lands on it again.
|
|
2053
|
+
if (view === 'overview' || view === 'insights') localStorage.setItem('cc-cost:view', view);
|
|
2018
2054
|
|
|
2019
2055
|
updateUrl();
|
|
2020
2056
|
await loadAndRender(view);
|
|
@@ -2566,10 +2602,15 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
2566
2602
|
currentProjectPath = state.project;
|
|
2567
2603
|
currentProjectName = state.projectName;
|
|
2568
2604
|
await navigate('sessions', { project: state.project, projectName: state.projectName });
|
|
2605
|
+
} else if (state.view === 'insights') {
|
|
2606
|
+
await navigate('insights');
|
|
2569
2607
|
} else if (scopeProject) {
|
|
2570
2608
|
// Same landing rule as applyScope: a scope with no cursor of its own opens its sessions.
|
|
2571
2609
|
currentProjectName = scopeProjectName;
|
|
2572
2610
|
await navigate('sessions', { project: scopeProject, projectName: scopeProjectName });
|
|
2611
|
+
} else if (localStorage.getItem('cc-cost:view') === 'insights') {
|
|
2612
|
+
// No nav state for this tab — fall back to the last top-level tab from any session.
|
|
2613
|
+
await navigate('insights');
|
|
2573
2614
|
} else {
|
|
2574
2615
|
await navigate('overview');
|
|
2575
2616
|
}
|
package/public/index.html
CHANGED
|
@@ -87,6 +87,7 @@
|
|
|
87
87
|
</button>
|
|
88
88
|
<button class="topbar-btn" id="infoBtn" title="Help & About (?)" onclick="toggleHelpModal()">
|
|
89
89
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><circle cx="12" cy="17" r="0.5" fill="currentColor"/></svg>
|
|
90
|
+
<kbd>?</kbd>
|
|
90
91
|
</button>
|
|
91
92
|
<a class="topbar-btn" href="https://github.com/NikiforovAll/claude-code-cost" target="_blank" rel="noopener" title="GitHub">
|
|
92
93
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" stroke="none"><path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"/></svg>
|
package/public/style.css
CHANGED
|
@@ -47,9 +47,8 @@ body {
|
|
|
47
47
|
background: var(--bg-deep);
|
|
48
48
|
color: var(--text-primary);
|
|
49
49
|
line-height: 1.5;
|
|
50
|
-
height:
|
|
50
|
+
height: 100vh;
|
|
51
51
|
display: flex;
|
|
52
|
-
zoom: 1.1;
|
|
53
52
|
flex-direction: column;
|
|
54
53
|
overflow: hidden;
|
|
55
54
|
-webkit-font-smoothing: antialiased;
|
|
@@ -1158,13 +1157,19 @@ body {
|
|
|
1158
1157
|
color: var(--text-primary);
|
|
1159
1158
|
}
|
|
1160
1159
|
|
|
1161
|
-
|
|
1160
|
+
kbd {
|
|
1162
1161
|
background: var(--bg-hover);
|
|
1163
|
-
padding:
|
|
1162
|
+
padding: 2px 6px;
|
|
1164
1163
|
border-radius: 4px;
|
|
1165
1164
|
font-family: var(--mono);
|
|
1166
1165
|
font-size: 11px;
|
|
1167
1166
|
border: 1px solid var(--border);
|
|
1167
|
+
color: var(--text-secondary);
|
|
1168
|
+
white-space: nowrap;
|
|
1169
|
+
}
|
|
1170
|
+
.topbar-btn kbd {
|
|
1171
|
+
font-size: 10px;
|
|
1172
|
+
line-height: 1;
|
|
1168
1173
|
}
|
|
1169
1174
|
|
|
1170
1175
|
/* #endregion */
|
|
@@ -1324,7 +1329,7 @@ body {
|
|
|
1324
1329
|
body.light {
|
|
1325
1330
|
--bg-deep: #e8e6e3;
|
|
1326
1331
|
--bg-surface: #efede9;
|
|
1327
|
-
--bg-elevated: #
|
|
1332
|
+
--bg-elevated: #f7f4f0;
|
|
1328
1333
|
--bg-hover: #d2d0cc;
|
|
1329
1334
|
--border: #cfcbc4;
|
|
1330
1335
|
--text-primary: #0a0a0a;
|
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
|
|