claude-code-cost 1.4.0 → 1.5.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 +2 -1
- package/public/app.js +155 -3
- package/public/style.css +84 -1
- package/public/vendor/claude-hub-sdk.js +20 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-cost",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Cost dashboard for Claude Code usage",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"open": "^11.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"@biomejs/biome": "2.4.10",
|
|
24
25
|
"husky": "^9.0.0"
|
|
25
26
|
},
|
|
26
27
|
"keywords": [
|
package/public/app.js
CHANGED
|
@@ -478,7 +478,13 @@ function cacheData(key, data) {
|
|
|
478
478
|
}
|
|
479
479
|
|
|
480
480
|
function isPrefKey(k) {
|
|
481
|
-
return
|
|
481
|
+
return (
|
|
482
|
+
k.startsWith('cc-cost:sort:') ||
|
|
483
|
+
k === 'cc-cost:range' ||
|
|
484
|
+
k === 'cc-cost:scope' ||
|
|
485
|
+
k === 'cc-cost:view' ||
|
|
486
|
+
k === 'cc-cost:share'
|
|
487
|
+
);
|
|
482
488
|
}
|
|
483
489
|
|
|
484
490
|
// Earlier versions persisted API payloads under cc-cost:<url>; drop what they left behind.
|
|
@@ -1094,6 +1100,7 @@ function renderDetail() {
|
|
|
1094
1100
|
const h = JSON.stringify(d);
|
|
1095
1101
|
if (lastRenderHash.detail === h) return;
|
|
1096
1102
|
lastRenderHash.detail = h;
|
|
1103
|
+
const hasSubagents = d.messages.some((m) => m._subagent);
|
|
1097
1104
|
|
|
1098
1105
|
el.innerHTML = `
|
|
1099
1106
|
<div class="dashboard-content">
|
|
@@ -1150,7 +1157,7 @@ function renderDetail() {
|
|
|
1150
1157
|
${compactionNote(d.compactions)}
|
|
1151
1158
|
${workflowsSection(d)}
|
|
1152
1159
|
|
|
1153
|
-
<div class="charts-row" style="margin-bottom:20px">
|
|
1160
|
+
<div class="charts-row${hasSubagents ? ' with-share' : ''}" style="margin-bottom:20px">
|
|
1154
1161
|
<div class="chart-box">
|
|
1155
1162
|
<div class="chart-title">Cumulative Cost</div>
|
|
1156
1163
|
<canvas id="cumulativeChart"></canvas>
|
|
@@ -1159,6 +1166,22 @@ function renderDetail() {
|
|
|
1159
1166
|
<div class="chart-title">Token Breakdown per Message</div>
|
|
1160
1167
|
<canvas id="tokenBreakdownChart"></canvas>
|
|
1161
1168
|
</div>
|
|
1169
|
+
${
|
|
1170
|
+
hasSubagents
|
|
1171
|
+
? `<div class="chart-box">
|
|
1172
|
+
<div class="chart-title share-head">Subagent Share
|
|
1173
|
+
<div class="seg" role="group" aria-label="Split by">
|
|
1174
|
+
<button type="button" class="seg-btn${shareMode === 'agent' ? ' on' : ''}" data-share="agent" onclick="setShareMode('agent')">by agent</button>
|
|
1175
|
+
<button type="button" class="seg-btn${shareMode === 'type' ? ' on' : ''}" data-share="type" onclick="setShareMode('type')">by type</button>
|
|
1176
|
+
</div>
|
|
1177
|
+
</div>
|
|
1178
|
+
<div class="share-body">
|
|
1179
|
+
<div class="share-pie"><canvas id="subagentShareChart"></canvas></div>
|
|
1180
|
+
<ul class="share-legend" id="subagentShareLegend"></ul>
|
|
1181
|
+
</div>
|
|
1182
|
+
</div>`
|
|
1183
|
+
: ''
|
|
1184
|
+
}
|
|
1162
1185
|
</div>
|
|
1163
1186
|
|
|
1164
1187
|
${rangeBrushHtml(d.messages.length)}
|
|
@@ -1183,6 +1206,7 @@ function renderDetail() {
|
|
|
1183
1206
|
requestAnimationFrame(() => {
|
|
1184
1207
|
destroyChart('cumulative');
|
|
1185
1208
|
destroyChart('tokenBreakdown');
|
|
1209
|
+
destroyChart('subagentShare');
|
|
1186
1210
|
const range = detailRangeFor(d);
|
|
1187
1211
|
applyDetailRange(d.messages, range);
|
|
1188
1212
|
initRangeBrush(d.messages, d.workflows, range);
|
|
@@ -1287,11 +1311,15 @@ function renderMessageRows(slice, total) {
|
|
|
1287
1311
|
body.innerHTML = rows.join('');
|
|
1288
1312
|
}
|
|
1289
1313
|
|
|
1314
|
+
function subagentKind(sa) {
|
|
1315
|
+
return sa.workflowId ? 'workflow' : sa.agentType || 'agent';
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1290
1318
|
function buildMessageRow(m) {
|
|
1291
1319
|
const sa = m._subagent;
|
|
1292
1320
|
const toolTags = !sa && m.tools ? m.tools.map((t) => `<span class="tool-tag">${esc(t)}</span>`).join(' ') : '';
|
|
1293
1321
|
const modelCol = sa
|
|
1294
|
-
? `<span class="model-badge">${esc(shortModel(m.model))}</span> <span class="subagent-tag">${esc(sa
|
|
1322
|
+
? `<span class="model-badge">${esc(shortModel(m.model))}</span> <span class="subagent-tag">${esc(subagentKind(sa))}</span>${sa.description ? ` <span class="subagent-desc">${esc(sa.description)}</span>` : ''}`
|
|
1295
1323
|
: `<span class="model-badge">${esc(shortModel(m.model))}</span>${toolTags ? ` ${toolTags}` : ''}`;
|
|
1296
1324
|
const rowAttrs = sa
|
|
1297
1325
|
? ` class="subagent-row" data-clickable onclick="navigateToAgent('${escAttrJs(sa.agentId)}')" title="${esc(`${sa.messageCount} turns · open subagent`)}"`
|
|
@@ -1710,6 +1738,129 @@ function renderTokenBreakdownChart(messages) {
|
|
|
1710
1738
|
markCompactions(charts.tokenBreakdown, messages, c);
|
|
1711
1739
|
}
|
|
1712
1740
|
|
|
1741
|
+
let shareMode = localStorage.getItem('cc-cost:share') === 'type' ? 'type' : 'agent';
|
|
1742
|
+
window.setShareMode = setShareMode;
|
|
1743
|
+
|
|
1744
|
+
function setShareMode(mode) {
|
|
1745
|
+
shareMode = mode;
|
|
1746
|
+
localStorage.setItem('cc-cost:share', mode);
|
|
1747
|
+
for (const b of document.querySelectorAll('[data-share]')) b.classList.toggle('on', b.dataset.share === mode);
|
|
1748
|
+
syncSubagentShare(detailSlice, getChartColors());
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
function syncSubagentShare(messages, c) {
|
|
1752
|
+
const chart = charts.subagentShare;
|
|
1753
|
+
if (!chart) return renderSubagentShareChart(messages);
|
|
1754
|
+
chart.data = subagentShareChartData(messages, c);
|
|
1755
|
+
chart.update('none');
|
|
1756
|
+
renderSubagentShareLegend(chart.data.slices);
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
function shareLabel(s) {
|
|
1760
|
+
return s.type ? `${s.type} · ${s.name}` : s.name;
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
function subagentShareChartData(messages, c) {
|
|
1764
|
+
const groups = new Map();
|
|
1765
|
+
let main = 0;
|
|
1766
|
+
for (const m of messages) {
|
|
1767
|
+
const sa = m._subagent;
|
|
1768
|
+
if (!sa) {
|
|
1769
|
+
main += m.cost;
|
|
1770
|
+
continue;
|
|
1771
|
+
}
|
|
1772
|
+
const kind = subagentKind(sa);
|
|
1773
|
+
const key = shareMode === 'type' ? kind : sa.agentId;
|
|
1774
|
+
let group = groups.get(key);
|
|
1775
|
+
if (!group) {
|
|
1776
|
+
group =
|
|
1777
|
+
shareMode === 'type'
|
|
1778
|
+
? { name: kind, cost: 0 }
|
|
1779
|
+
: { name: sa.description || kind, type: sa.agentType, agentId: sa.agentId, cost: 0 };
|
|
1780
|
+
groups.set(key, group);
|
|
1781
|
+
}
|
|
1782
|
+
group.cost += m.cost;
|
|
1783
|
+
}
|
|
1784
|
+
const palette = chartPalette(c);
|
|
1785
|
+
const agents = [...groups.values()].sort((a, b) => b.cost - a.cost);
|
|
1786
|
+
// The main loop keeps the accent wherever it ranks; agents cycle through the other five colors.
|
|
1787
|
+
const slices = [
|
|
1788
|
+
{ name: 'main', cost: main, color: palette[0] },
|
|
1789
|
+
...agents.map((a, i) => ({ ...a, color: palette[1 + (i % (palette.length - 1))] })),
|
|
1790
|
+
].sort((a, b) => b.cost - a.cost);
|
|
1791
|
+
const colors = slices.map((s) => s.color);
|
|
1792
|
+
return {
|
|
1793
|
+
labels: slices.map((s) => s.name),
|
|
1794
|
+
slices,
|
|
1795
|
+
datasets: [
|
|
1796
|
+
{
|
|
1797
|
+
...barDataset(
|
|
1798
|
+
slices.map((s) => s.cost),
|
|
1799
|
+
colors,
|
|
1800
|
+
),
|
|
1801
|
+
borderRadius: 0,
|
|
1802
|
+
},
|
|
1803
|
+
],
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
function renderSubagentShareChart(messages) {
|
|
1808
|
+
const canvas = document.getElementById('subagentShareChart');
|
|
1809
|
+
if (!canvas || !messages?.length) return;
|
|
1810
|
+
destroyChart('subagentShare');
|
|
1811
|
+
|
|
1812
|
+
const c = getChartColors();
|
|
1813
|
+
const { scales: _scales, ...defaults } = chartDefaults(c);
|
|
1814
|
+
|
|
1815
|
+
charts.subagentShare = new Chart(canvas, {
|
|
1816
|
+
type: 'doughnut',
|
|
1817
|
+
data: subagentShareChartData(messages, c),
|
|
1818
|
+
options: {
|
|
1819
|
+
...defaults,
|
|
1820
|
+
cutout: '55%',
|
|
1821
|
+
onClick: (_e, els, chart) => {
|
|
1822
|
+
const agentId = chart.data.slices[els[0]?.index]?.agentId;
|
|
1823
|
+
if (agentId) navigateToAgent(agentId);
|
|
1824
|
+
},
|
|
1825
|
+
onHover: (e, els, chart) => {
|
|
1826
|
+
e.native.target.style.cursor = chart.data.slices[els[0]?.index]?.agentId ? 'pointer' : '';
|
|
1827
|
+
},
|
|
1828
|
+
plugins: {
|
|
1829
|
+
...withTooltip(defaults, {
|
|
1830
|
+
title: (items) => {
|
|
1831
|
+
const s = items[0]?.chart.data.slices[items[0].dataIndex];
|
|
1832
|
+
return s ? shareLabel(s) : '';
|
|
1833
|
+
},
|
|
1834
|
+
label: (ctx) => {
|
|
1835
|
+
const total = ctx.dataset.data.reduce((s, v) => s + v, 0);
|
|
1836
|
+
return `${usd(ctx.parsed)} (${formatPct(ctx.parsed, total)}%)`;
|
|
1837
|
+
},
|
|
1838
|
+
}),
|
|
1839
|
+
},
|
|
1840
|
+
},
|
|
1841
|
+
});
|
|
1842
|
+
renderSubagentShareLegend(charts.subagentShare.data.slices);
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
// An HTML list, not the Chart.js legend: a session can have tens of agents, and a canvas legend
|
|
1846
|
+
// that runs out of room drops them.
|
|
1847
|
+
function renderSubagentShareLegend(slices) {
|
|
1848
|
+
const el = document.getElementById('subagentShareLegend');
|
|
1849
|
+
if (!el) return;
|
|
1850
|
+
const total = slices.reduce((s, x) => s + x.cost, 0);
|
|
1851
|
+
el.innerHTML = slices
|
|
1852
|
+
.map((s) => {
|
|
1853
|
+
const attrs = s.agentId ? ` class="share-agent" onclick="navigateToAgent('${escAttrJs(s.agentId)}')"` : '';
|
|
1854
|
+
return `<li${attrs} title="${esc(shareLabel(s))}">
|
|
1855
|
+
<span class="share-swatch" style="background:${hexToRgba(s.color, 0.5)};border-color:${s.color}"></span>
|
|
1856
|
+
<span class="share-name">${esc(s.name)}</span>
|
|
1857
|
+
<span class="share-cost">${formatCost(s.cost)}</span>
|
|
1858
|
+
<span class="share-pct">${formatPct(s.cost, total)}%</span>
|
|
1859
|
+
</li>`;
|
|
1860
|
+
})
|
|
1861
|
+
.join('');
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1713
1864
|
// #region RANGE BRUSH
|
|
1714
1865
|
// Long sessions squash both per-message charts into noise, so the detail view shows a window of
|
|
1715
1866
|
// the last DETAIL_WINDOW messages by default and lets the user drag that window across an overview
|
|
@@ -1799,6 +1950,7 @@ function applyDetailRange(messages, range) {
|
|
|
1799
1950
|
renderCumulativeChart(detailSlice);
|
|
1800
1951
|
renderTokenBreakdownChart(detailSlice);
|
|
1801
1952
|
}
|
|
1953
|
+
syncSubagentShare(detailSlice, c);
|
|
1802
1954
|
}
|
|
1803
1955
|
|
|
1804
1956
|
function rangeBrushHtml(total) {
|
package/public/style.css
CHANGED
|
@@ -752,6 +752,88 @@ body {
|
|
|
752
752
|
margin-bottom: 20px;
|
|
753
753
|
}
|
|
754
754
|
|
|
755
|
+
.charts-row.with-share {
|
|
756
|
+
grid-template-columns: 3fr 2fr 2fr;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
.share-head {
|
|
760
|
+
display: flex;
|
|
761
|
+
align-items: center;
|
|
762
|
+
justify-content: space-between;
|
|
763
|
+
gap: 8px;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
.share-body {
|
|
767
|
+
display: flex;
|
|
768
|
+
justify-content: center;
|
|
769
|
+
align-items: center;
|
|
770
|
+
gap: 16px;
|
|
771
|
+
height: 150px;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
.share-pie {
|
|
775
|
+
position: relative;
|
|
776
|
+
flex: 0 0 150px;
|
|
777
|
+
height: 100%;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
.share-legend {
|
|
781
|
+
display: grid;
|
|
782
|
+
grid-template-columns: 10px minmax(0, max-content) auto auto;
|
|
783
|
+
align-content: start;
|
|
784
|
+
justify-content: start;
|
|
785
|
+
column-gap: 8px;
|
|
786
|
+
min-width: 0;
|
|
787
|
+
max-height: 100%;
|
|
788
|
+
margin: 0;
|
|
789
|
+
padding: 0 8px 0 0;
|
|
790
|
+
list-style: none;
|
|
791
|
+
overflow-x: hidden;
|
|
792
|
+
overflow-y: auto;
|
|
793
|
+
font-family: var(--mono);
|
|
794
|
+
font-size: 10px;
|
|
795
|
+
color: var(--text-secondary);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
.share-legend li {
|
|
799
|
+
display: grid;
|
|
800
|
+
grid-column: 1 / -1;
|
|
801
|
+
grid-template-columns: subgrid;
|
|
802
|
+
align-items: center;
|
|
803
|
+
padding: 2px 0;
|
|
804
|
+
border-radius: 3px;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
.share-legend li.share-agent {
|
|
808
|
+
cursor: pointer;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
.share-legend li.share-agent:hover {
|
|
812
|
+
background: var(--bg-hover);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
.share-swatch {
|
|
816
|
+
width: 10px;
|
|
817
|
+
height: 10px;
|
|
818
|
+
border: 1px solid;
|
|
819
|
+
border-radius: 2px;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
.share-name {
|
|
823
|
+
overflow: hidden;
|
|
824
|
+
text-overflow: ellipsis;
|
|
825
|
+
white-space: nowrap;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
.share-cost {
|
|
829
|
+
color: var(--text-primary);
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
.share-pct {
|
|
833
|
+
text-align: right;
|
|
834
|
+
color: var(--text-muted);
|
|
835
|
+
}
|
|
836
|
+
|
|
755
837
|
.chart-box {
|
|
756
838
|
background: var(--bg-surface);
|
|
757
839
|
border: 1px solid var(--border);
|
|
@@ -2302,7 +2384,8 @@ body.light {
|
|
|
2302
2384
|
/* #region RESPONSIVE */
|
|
2303
2385
|
|
|
2304
2386
|
@media (max-width: 900px) {
|
|
2305
|
-
.charts-row
|
|
2387
|
+
.charts-row,
|
|
2388
|
+
.charts-row.with-share {
|
|
2306
2389
|
grid-template-columns: 1fr;
|
|
2307
2390
|
}
|
|
2308
2391
|
.cards-row {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// claude-hub-sdk 1.
|
|
1
|
+
// claude-hub-sdk 1.8.0 (sha256 9a67dd2aa534). Copied by npm run sdk:sync in claude-code-hub. Do not edit.
|
|
2
2
|
// Claude Code Hub SDK: the one rule that names a key press, shared by the hub page, client.js and
|
|
3
3
|
// stub.js. The hub serves it to its page as /sdk/keys.js; mount() and sdk:sync put it in front of
|
|
4
4
|
// client.js and stub.js, so an app still loads one file.
|
|
@@ -33,7 +33,21 @@ var ClaudeHubKeys = (() => {
|
|
|
33
33
|
return combo.split('+').map((k) => mods[k] ?? named[k] ?? (k.length === 1 ? k.toUpperCase() : k));
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
// A host claim (protocol §5.2) names a press by its physical code, or by its character when the layout
|
|
37
|
+
// moves the key: {ctrlKey?, altKey?, shiftKey?, metaKey?, code, key: 'Unidentified'} or {…, key, code: ''}.
|
|
38
|
+
// A press matches a claim when one of its two signatures is the claim's first. AltGr types a
|
|
39
|
+
// character, so its press matches by character only. cck's frames use the same format.
|
|
40
|
+
function keySigs(e) {
|
|
41
|
+
const mods = [e.ctrlKey && 'ctrl', e.altKey && 'alt', e.shiftKey && 'shift', e.metaKey && 'meta']
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.join('+');
|
|
44
|
+
return [
|
|
45
|
+
e.code && !e.getModifierState?.('AltGraph') && `${mods}|c:${e.code}`,
|
|
46
|
+
typeof e.key === 'string' && e.key !== 'Unidentified' && `${mods}|k:${e.key.toLowerCase()}`,
|
|
47
|
+
].filter(Boolean);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { comboOf, keyParts, keySigs };
|
|
37
51
|
})();
|
|
38
52
|
|
|
39
53
|
if (typeof module === 'object' && module.exports) module.exports = ClaudeHubKeys;
|
|
@@ -60,6 +74,8 @@ if (typeof module === 'object' && module.exports) module.exports = ClaudeHubKeys
|
|
|
60
74
|
status: 'standalone',
|
|
61
75
|
themes: [],
|
|
62
76
|
inHub: false,
|
|
77
|
+
settings: null,
|
|
78
|
+
onSettings: () => off,
|
|
63
79
|
onStatus: () => off,
|
|
64
80
|
onActive: () => off,
|
|
65
81
|
onThemes: () => off,
|
|
@@ -67,9 +83,10 @@ if (typeof module === 'object' && module.exports) module.exports = ClaudeHubKeys
|
|
|
67
83
|
bindTheme: () => off,
|
|
68
84
|
handle() {},
|
|
69
85
|
publish() {},
|
|
70
|
-
invoke(action, params = {}) {
|
|
86
|
+
invoke(action, params = {}, opts = {}) {
|
|
71
87
|
const target = standaloneFn(action)?.(params);
|
|
72
88
|
if (!target) return Promise.resolve({ ok: false, reason: 'unhandled' });
|
|
89
|
+
if (opts.open === 'pane') return Promise.resolve({ ok: true, handledBy: 'standalone', url: target });
|
|
73
90
|
win.open(target, '_blank', 'noopener');
|
|
74
91
|
return Promise.resolve({ ok: true, handledBy: 'standalone' });
|
|
75
92
|
},
|