claude-code-cost 1.3.2 → 1.5.0
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/README.md +2 -0
- package/hub-app.json +2 -1
- package/lib/app.js +227 -0
- package/lib/cli.js +661 -0
- package/lib/costs.js +1634 -0
- package/package.json +1 -1
- package/public/app.js +236 -28
- package/public/style.css +142 -1
- package/server.js +6 -1605
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -15,6 +15,7 @@ let currentProjectName = null;
|
|
|
15
15
|
let scopeProject = null;
|
|
16
16
|
let scopeProjectName = null;
|
|
17
17
|
let currentSessionId = null;
|
|
18
|
+
let currentAgentId = null;
|
|
18
19
|
let lastSelectedProject = null;
|
|
19
20
|
let lastSelectedSession = null;
|
|
20
21
|
const DEFAULT_SORT = {
|
|
@@ -255,6 +256,7 @@ function getUrlState() {
|
|
|
255
256
|
project: p.get('project'),
|
|
256
257
|
projectName: p.get('projectName'),
|
|
257
258
|
session: p.get('session'),
|
|
259
|
+
agent: p.get('agent'),
|
|
258
260
|
};
|
|
259
261
|
}
|
|
260
262
|
|
|
@@ -435,6 +437,7 @@ function updateUrl() {
|
|
|
435
437
|
if (currentProjectPath) p.set('project', currentProjectPath);
|
|
436
438
|
if (currentProjectName) p.set('projectName', currentProjectName);
|
|
437
439
|
if (currentSessionId) p.set('session', currentSessionId);
|
|
440
|
+
if (currentAgentId) p.set('agent', currentAgentId);
|
|
438
441
|
const qs = p.toString();
|
|
439
442
|
history.replaceState(null, '', qs ? `?${qs}` : '/');
|
|
440
443
|
sessionStorage.setItem('cc-cost:nav', qs);
|
|
@@ -475,7 +478,13 @@ function cacheData(key, data) {
|
|
|
475
478
|
}
|
|
476
479
|
|
|
477
480
|
function isPrefKey(k) {
|
|
478
|
-
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
|
+
);
|
|
479
488
|
}
|
|
480
489
|
|
|
481
490
|
// Earlier versions persisted API payloads under cc-cost:<url>; drop what they left behind.
|
|
@@ -568,8 +577,12 @@ async function fetchSessions(encodedPath) {
|
|
|
568
577
|
sessionsModelDistribution = data.modelDistribution || [];
|
|
569
578
|
}
|
|
570
579
|
|
|
571
|
-
async function fetchSessionDetail(sessionId) {
|
|
572
|
-
|
|
580
|
+
async function fetchSessionDetail(sessionId, agentId) {
|
|
581
|
+
const agentPath = agentId ? `/agents/${encodeURIComponent(agentId)}` : '';
|
|
582
|
+
sessionDetailData = await fetchJSON(
|
|
583
|
+
`/api/sessions/${encodeURIComponent(sessionId)}${agentPath}?${rangeParams()}`,
|
|
584
|
+
true,
|
|
585
|
+
);
|
|
573
586
|
// Populate project context when opening via deep link (no project in URL)
|
|
574
587
|
if (sessionDetailData && !currentProjectPath) {
|
|
575
588
|
currentProjectPath = sessionDetailData.encodedProjectPath;
|
|
@@ -1087,6 +1100,7 @@ function renderDetail() {
|
|
|
1087
1100
|
const h = JSON.stringify(d);
|
|
1088
1101
|
if (lastRenderHash.detail === h) return;
|
|
1089
1102
|
lastRenderHash.detail = h;
|
|
1103
|
+
const hasSubagents = d.messages.some((m) => m._subagent);
|
|
1090
1104
|
|
|
1091
1105
|
el.innerHTML = `
|
|
1092
1106
|
<div class="dashboard-content">
|
|
@@ -1095,9 +1109,16 @@ function renderDetail() {
|
|
|
1095
1109
|
<span class="sep">/</span>
|
|
1096
1110
|
<a onclick="navigateToSessions('${escAttrJs(d.encodedProjectPath)}', '${escAttrJs(d.projectPath)}')">${esc(d.projectPath)}</a>
|
|
1097
1111
|
<span class="sep">/</span>
|
|
1098
|
-
|
|
1112
|
+
${
|
|
1113
|
+
d.agentId
|
|
1114
|
+
? `<a onclick="navigateToDetail('${escAttrJs(d.sessionId)}')">${esc(d.sessionTitle)}</a>
|
|
1115
|
+
<span class="sep">/</span>
|
|
1116
|
+
<span class="current">${esc(d.description || d.agentId)}</span>`
|
|
1117
|
+
: `<span class="current">${esc(d.customTitle || d.firstPrompt || d.sessionId)}</span>`
|
|
1118
|
+
}
|
|
1099
1119
|
</div>
|
|
1100
1120
|
|
|
1121
|
+
${d.agentId ? `<div class="detail-agent-type"><span class="subagent-tag">${esc(d.agentType)}</span> ${esc(d.agentId)}</div>` : ''}
|
|
1101
1122
|
${d.firstPrompt ? `<div style="color:var(--text-tertiary);font-size:12px;margin-bottom:16px;font-style:italic">"${esc(d.firstPrompt)}"</div>` : ''}
|
|
1102
1123
|
|
|
1103
1124
|
<div class="detail-header">
|
|
@@ -1136,7 +1157,7 @@ function renderDetail() {
|
|
|
1136
1157
|
${compactionNote(d.compactions)}
|
|
1137
1158
|
${workflowsSection(d)}
|
|
1138
1159
|
|
|
1139
|
-
<div class="charts-row" style="margin-bottom:20px">
|
|
1160
|
+
<div class="charts-row${hasSubagents ? ' with-share' : ''}" style="margin-bottom:20px">
|
|
1140
1161
|
<div class="chart-box">
|
|
1141
1162
|
<div class="chart-title">Cumulative Cost</div>
|
|
1142
1163
|
<canvas id="cumulativeChart"></canvas>
|
|
@@ -1145,6 +1166,22 @@ function renderDetail() {
|
|
|
1145
1166
|
<div class="chart-title">Token Breakdown per Message</div>
|
|
1146
1167
|
<canvas id="tokenBreakdownChart"></canvas>
|
|
1147
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
|
+
}
|
|
1148
1185
|
</div>
|
|
1149
1186
|
|
|
1150
1187
|
${rangeBrushHtml(d.messages.length)}
|
|
@@ -1169,8 +1206,10 @@ function renderDetail() {
|
|
|
1169
1206
|
requestAnimationFrame(() => {
|
|
1170
1207
|
destroyChart('cumulative');
|
|
1171
1208
|
destroyChart('tokenBreakdown');
|
|
1172
|
-
|
|
1173
|
-
|
|
1209
|
+
destroyChart('subagentShare');
|
|
1210
|
+
const range = detailRangeFor(d);
|
|
1211
|
+
applyDetailRange(d.messages, range);
|
|
1212
|
+
initRangeBrush(d.messages, d.workflows, range);
|
|
1174
1213
|
});
|
|
1175
1214
|
}
|
|
1176
1215
|
|
|
@@ -1272,13 +1311,20 @@ function renderMessageRows(slice, total) {
|
|
|
1272
1311
|
body.innerHTML = rows.join('');
|
|
1273
1312
|
}
|
|
1274
1313
|
|
|
1314
|
+
function subagentKind(sa) {
|
|
1315
|
+
return sa.workflowId ? 'workflow' : sa.agentType || 'agent';
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1275
1318
|
function buildMessageRow(m) {
|
|
1276
1319
|
const sa = m._subagent;
|
|
1277
1320
|
const toolTags = !sa && m.tools ? m.tools.map((t) => `<span class="tool-tag">${esc(t)}</span>`).join(' ') : '';
|
|
1278
1321
|
const modelCol = sa
|
|
1279
|
-
? `<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>` : ''}`
|
|
1280
1323
|
: `<span class="model-badge">${esc(shortModel(m.model))}</span>${toolTags ? ` ${toolTags}` : ''}`;
|
|
1281
|
-
|
|
1324
|
+
const rowAttrs = sa
|
|
1325
|
+
? ` class="subagent-row" data-clickable onclick="navigateToAgent('${escAttrJs(sa.agentId)}')" title="${esc(`${sa.messageCount} turns · open subagent`)}"`
|
|
1326
|
+
: '';
|
|
1327
|
+
return `<tr${rowAttrs}>
|
|
1282
1328
|
<td class="muted">${m.index}</td>
|
|
1283
1329
|
<td class="muted">${localTime(m.timestamp)}</td>
|
|
1284
1330
|
<td>${modelCol}</td>
|
|
@@ -1692,6 +1738,129 @@ function renderTokenBreakdownChart(messages) {
|
|
|
1692
1738
|
markCompactions(charts.tokenBreakdown, messages, c);
|
|
1693
1739
|
}
|
|
1694
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
|
+
|
|
1695
1864
|
// #region RANGE BRUSH
|
|
1696
1865
|
// Long sessions squash both per-message charts into noise, so the detail view shows a window of
|
|
1697
1866
|
// the last DETAIL_WINDOW messages by default and lets the user drag that window across an overview
|
|
@@ -1700,7 +1869,8 @@ function renderTokenBreakdownChart(messages) {
|
|
|
1700
1869
|
const DETAIL_WINDOW_PRESETS = [25, 50, 100, 200];
|
|
1701
1870
|
const DETAIL_WINDOW = DETAIL_WINDOW_PRESETS[0];
|
|
1702
1871
|
const DETAIL_WINDOW_MIN = 10;
|
|
1703
|
-
|
|
1872
|
+
// Keyed by session or session/agent, so backing out of a subagent returns to the same window.
|
|
1873
|
+
const detailRanges = new Map();
|
|
1704
1874
|
let detailSlice = [];
|
|
1705
1875
|
|
|
1706
1876
|
function median(sorted) {
|
|
@@ -1713,6 +1883,14 @@ function median(sorted) {
|
|
|
1713
1883
|
// surface their own outliers; the absolute floor drops noise in tiny sessions.
|
|
1714
1884
|
const CACHE_BURST_RATIO = 4;
|
|
1715
1885
|
const CACHE_BURST_MIN_TOKENS = 20000;
|
|
1886
|
+
const SUBAGENT_COSTLY_USD = 1;
|
|
1887
|
+
const MARKER_KINDS = {
|
|
1888
|
+
burst: { cls: '', label: 'cache burst' },
|
|
1889
|
+
compaction: { cls: 'compact', label: 'compaction' },
|
|
1890
|
+
agent: { cls: 'agent', label: 'subagent' },
|
|
1891
|
+
costlyAgent: { cls: 'agent costly', label: 'subagent', suffix: ` ≥ ${formatCost(SUBAGENT_COSTLY_USD)}` },
|
|
1892
|
+
workflow: { cls: 'workflow', label: 'workflow' },
|
|
1893
|
+
};
|
|
1716
1894
|
|
|
1717
1895
|
// A compaction explains the burst on the turn that follows it, so that turn is labelled
|
|
1718
1896
|
// `compaction`; `burst` is left for the re-caches with no boundary behind them.
|
|
@@ -1728,7 +1906,12 @@ function notableEvents(messages) {
|
|
|
1728
1906
|
const tip = `#${m.index} · ${c.trigger} compaction ${formatTokens(c.preTokens)} → ${formatTokens(c.postTokens)} · ~${formatCost(c.estCost)}`;
|
|
1729
1907
|
return [{ i, kind: 'compaction', tip }];
|
|
1730
1908
|
}
|
|
1731
|
-
|
|
1909
|
+
const sa = m._subagent;
|
|
1910
|
+
if (sa && !sa.workflowId) {
|
|
1911
|
+
const tip = `#${m.index} · ${sa.agentType}${sa.description ? ` · ${sa.description}` : ''} · ${formatCost(m.cost)}`;
|
|
1912
|
+
return [{ i, kind: m.cost >= SUBAGENT_COSTLY_USD ? 'costlyAgent' : 'agent', tip }];
|
|
1913
|
+
}
|
|
1914
|
+
if (!sa && m.cacheCreationTokens >= threshold) {
|
|
1732
1915
|
return [{ i, kind: 'burst', tip: `#${m.index} · cache write ${formatTokens(m.cacheCreationTokens)}` }];
|
|
1733
1916
|
}
|
|
1734
1917
|
return [];
|
|
@@ -1742,12 +1925,14 @@ function clampRange(start, end, total) {
|
|
|
1742
1925
|
|
|
1743
1926
|
function detailRangeFor(d) {
|
|
1744
1927
|
const total = d.messages.length;
|
|
1745
|
-
const
|
|
1928
|
+
const key = d.agentId ? `${d.sessionId}/${d.agentId}` : d.sessionId;
|
|
1929
|
+
const prev = detailRanges.get(key) || null;
|
|
1746
1930
|
const size = prev ? prev.end - prev.start : DETAIL_WINDOW;
|
|
1747
1931
|
const atTail = !prev || prev.end === prev.total;
|
|
1748
1932
|
const start = atTail ? total - size : prev.start;
|
|
1749
|
-
|
|
1750
|
-
|
|
1933
|
+
const range = { total, ...clampRange(start, start + size, total) };
|
|
1934
|
+
detailRanges.set(key, range);
|
|
1935
|
+
return range;
|
|
1751
1936
|
}
|
|
1752
1937
|
|
|
1753
1938
|
function applyDetailRange(messages, range) {
|
|
@@ -1765,6 +1950,7 @@ function applyDetailRange(messages, range) {
|
|
|
1765
1950
|
renderCumulativeChart(detailSlice);
|
|
1766
1951
|
renderTokenBreakdownChart(detailSlice);
|
|
1767
1952
|
}
|
|
1953
|
+
syncSubagentShare(detailSlice, c);
|
|
1768
1954
|
}
|
|
1769
1955
|
|
|
1770
1956
|
function rangeBrushHtml(total) {
|
|
@@ -1799,11 +1985,10 @@ function rangeBrushHtml(total) {
|
|
|
1799
1985
|
const rangeOverviewSvg =
|
|
1800
1986
|
'<svg class="rb-overview" viewBox="0 0 1000 100" preserveAspectRatio="none" aria-hidden="true"><polygon /><polyline /></svg>';
|
|
1801
1987
|
|
|
1802
|
-
function initRangeBrush(messages, workflows) {
|
|
1988
|
+
function initRangeBrush(messages, workflows, range) {
|
|
1803
1989
|
const root = document.getElementById('rangeBrush');
|
|
1804
1990
|
if (!root) return;
|
|
1805
1991
|
const total = messages.length;
|
|
1806
|
-
const range = detailRange;
|
|
1807
1992
|
const q = (sel) => root.querySelector(sel);
|
|
1808
1993
|
const track = q('.rb-track');
|
|
1809
1994
|
const win = q('.rb-window');
|
|
@@ -1831,17 +2016,18 @@ function initRangeBrush(messages, workflows) {
|
|
|
1831
2016
|
burstsEl.innerHTML = markers
|
|
1832
2017
|
.map(
|
|
1833
2018
|
(k) =>
|
|
1834
|
-
`<button type="button" class="rb-burst${k.kind
|
|
2019
|
+
`<button type="button" class="rb-burst ${esc(MARKER_KINDS[k.kind].cls)}" data-i="${esc(String(k.i))}" style="left:${((k.i + 0.5) / total) * 100}%" title="${esc(k.tip)}" aria-label="${esc(k.tip)}"></button>`,
|
|
1835
2020
|
)
|
|
1836
2021
|
.join('');
|
|
1837
2022
|
const burstEls = [...burstsEl.children].map((el, k) => ({ el, i: markers[k].i }));
|
|
1838
|
-
const
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
[
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
2023
|
+
const tally = { workflow: runs.length };
|
|
2024
|
+
for (const k of markers) tally[k.kind] = (tally[k.kind] || 0) + 1;
|
|
2025
|
+
const counts = Object.entries(MARKER_KINDS)
|
|
2026
|
+
.filter(([kind]) => tally[kind])
|
|
2027
|
+
.map(([kind, { cls, label, suffix = '' }]) => {
|
|
2028
|
+
const n = tally[kind];
|
|
2029
|
+
return `<span class="${esc(cls)}"><i></i>${n} ${label}${n === 1 ? '' : 's'}${suffix}</span>`;
|
|
2030
|
+
});
|
|
1845
2031
|
if (counts.length) {
|
|
1846
2032
|
burstCount.hidden = false;
|
|
1847
2033
|
burstCount.innerHTML = counts.join('<span class="rb-sep">·</span>');
|
|
@@ -2498,11 +2684,18 @@ function showView(viewId) {
|
|
|
2498
2684
|
if (el) el.classList.add('active');
|
|
2499
2685
|
}
|
|
2500
2686
|
|
|
2687
|
+
function agentFor(view, agent) {
|
|
2688
|
+
return view === 'detail' ? agent || null : null;
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2501
2691
|
async function navigate(view, params) {
|
|
2502
2692
|
currentView = view;
|
|
2503
2693
|
if (params?.project) currentProjectPath = params.project;
|
|
2504
2694
|
if (params?.projectName) currentProjectName = params.projectName;
|
|
2505
2695
|
if (params?.session) currentSessionId = params.session;
|
|
2696
|
+
const nextAgent = agentFor(view, params?.agent);
|
|
2697
|
+
if (nextAgent !== currentAgentId) sessionDetailData = null;
|
|
2698
|
+
currentAgentId = nextAgent;
|
|
2506
2699
|
|
|
2507
2700
|
// Clear downstream state
|
|
2508
2701
|
if (view === 'overview' || view === 'insights') {
|
|
@@ -2534,6 +2727,10 @@ async function navigateToDetail(sessionId) {
|
|
|
2534
2727
|
await navigate('detail', { session: sessionId });
|
|
2535
2728
|
}
|
|
2536
2729
|
|
|
2730
|
+
async function navigateToAgent(agentId, sessionId = currentSessionId) {
|
|
2731
|
+
await navigate('detail', { session: sessionId, agent: agentId });
|
|
2732
|
+
}
|
|
2733
|
+
|
|
2537
2734
|
// biome-ignore lint/correctness/noUnusedVariables: called from HTML onclick
|
|
2538
2735
|
function sortBy(field) {
|
|
2539
2736
|
const s = currentSort();
|
|
@@ -2677,7 +2874,7 @@ async function loadAndRender(view) {
|
|
|
2677
2874
|
lastRenderHash.detail = null;
|
|
2678
2875
|
renderDetail();
|
|
2679
2876
|
}
|
|
2680
|
-
await fetchSessionDetail(currentSessionId);
|
|
2877
|
+
await fetchSessionDetail(currentSessionId, currentAgentId);
|
|
2681
2878
|
if (myNav !== navCounter) return;
|
|
2682
2879
|
renderDetail();
|
|
2683
2880
|
}
|
|
@@ -2692,8 +2889,13 @@ async function loadAndRender(view) {
|
|
|
2692
2889
|
// stale cursor, not a broken app: drop it and land on the overview.
|
|
2693
2890
|
if (err.status === 404 && view === 'detail') {
|
|
2694
2891
|
sessionDetailData = null;
|
|
2695
|
-
|
|
2696
|
-
|
|
2892
|
+
if (currentAgentId) {
|
|
2893
|
+
showToast('Subagent not found — showing session');
|
|
2894
|
+
await navigateToDetail(currentSessionId);
|
|
2895
|
+
} else {
|
|
2896
|
+
showToast('Not in this config dir — showing overview');
|
|
2897
|
+
await navigate('overview');
|
|
2898
|
+
}
|
|
2697
2899
|
return;
|
|
2698
2900
|
}
|
|
2699
2901
|
showToast(`Error: ${err.message}`);
|
|
@@ -3222,6 +3424,10 @@ function activateSelectedRow() {
|
|
|
3222
3424
|
|
|
3223
3425
|
async function goBack() {
|
|
3224
3426
|
let target;
|
|
3427
|
+
if (currentView === 'detail' && currentAgentId) {
|
|
3428
|
+
await navigateToDetail(currentSessionId);
|
|
3429
|
+
return;
|
|
3430
|
+
}
|
|
3225
3431
|
if (currentView === 'detail') {
|
|
3226
3432
|
target = currentProjectPath ? 'sessions' : 'overview';
|
|
3227
3433
|
} else if (currentView === 'sessions' || currentView === 'insights') {
|
|
@@ -3427,6 +3633,7 @@ hub.subscribe('project.changed', (p) => {
|
|
|
3427
3633
|
});
|
|
3428
3634
|
|
|
3429
3635
|
hub.handle('session.cost', (p) => p.session && navigateToDetail(p.session));
|
|
3636
|
+
hub.handle('agent.cost', (p) => navigateToAgent(p.agent, p.session));
|
|
3430
3637
|
|
|
3431
3638
|
(function initHubTheme() {
|
|
3432
3639
|
const getTheme = () => (document.body.classList.contains('light') ? 'light' : 'dark');
|
|
@@ -3491,7 +3698,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|
|
3491
3698
|
currentSessionId = state.session;
|
|
3492
3699
|
currentProjectPath = state.project;
|
|
3493
3700
|
currentProjectName = state.projectName;
|
|
3494
|
-
await navigate('detail', { session: state.session });
|
|
3701
|
+
await navigate('detail', { session: state.session, agent: state.agent });
|
|
3495
3702
|
} else if (state.project) {
|
|
3496
3703
|
currentProjectPath = state.project;
|
|
3497
3704
|
currentProjectName = state.projectName;
|
|
@@ -3516,6 +3723,7 @@ window.addEventListener('popstate', () => {
|
|
|
3516
3723
|
currentProjectPath = state.project;
|
|
3517
3724
|
currentProjectName = state.projectName;
|
|
3518
3725
|
currentSessionId = state.session;
|
|
3726
|
+
currentAgentId = agentFor(state.view, state.agent);
|
|
3519
3727
|
lastRenderHash = {};
|
|
3520
3728
|
loadAndRender(currentView);
|
|
3521
3729
|
});
|
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);
|
|
@@ -1018,6 +1100,39 @@ body {
|
|
|
1018
1100
|
background: var(--compact);
|
|
1019
1101
|
}
|
|
1020
1102
|
|
|
1103
|
+
.rb-burst.agent::before,
|
|
1104
|
+
.rb-burst.agent::after {
|
|
1105
|
+
background: var(--text-tertiary);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
.rb-burst.agent::after {
|
|
1109
|
+
top: auto;
|
|
1110
|
+
bottom: 3px;
|
|
1111
|
+
border-radius: 1px;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
.rb-burst.costly::before,
|
|
1115
|
+
.rb-burst.costly::after {
|
|
1116
|
+
background: var(--error);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
.rb-burst-count .agent {
|
|
1120
|
+
color: var(--text-tertiary);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
.rb-burst-count .agent i {
|
|
1124
|
+
border-radius: 1px;
|
|
1125
|
+
background: var(--text-tertiary);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
.rb-burst-count .costly {
|
|
1129
|
+
color: var(--error);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
.rb-burst-count .costly i {
|
|
1133
|
+
background: var(--error);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1021
1136
|
/* The shade outside the window is the window's own shadow, clipped by the track. */
|
|
1022
1137
|
.rb-window {
|
|
1023
1138
|
position: absolute;
|
|
@@ -1328,6 +1443,31 @@ body.light .rb-window {
|
|
|
1328
1443
|
background: var(--bg-hover);
|
|
1329
1444
|
}
|
|
1330
1445
|
|
|
1446
|
+
.subagent-desc {
|
|
1447
|
+
font-size: 11px;
|
|
1448
|
+
color: var(--text-secondary);
|
|
1449
|
+
margin-left: 4px;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
.subagent-row {
|
|
1453
|
+
cursor: pointer;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
.subagent-row:hover .subagent-desc {
|
|
1457
|
+
color: var(--accent-text);
|
|
1458
|
+
text-decoration: underline;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
.detail-agent-type {
|
|
1462
|
+
color: var(--text-tertiary);
|
|
1463
|
+
font-size: 12px;
|
|
1464
|
+
margin-bottom: 16px;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
.detail-agent-type .subagent-tag {
|
|
1468
|
+
margin-left: 0;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1331
1471
|
.tool-tag {
|
|
1332
1472
|
text-transform: lowercase;
|
|
1333
1473
|
color: var(--chart-2, #60a5fa);
|
|
@@ -2244,7 +2384,8 @@ body.light {
|
|
|
2244
2384
|
/* #region RESPONSIVE */
|
|
2245
2385
|
|
|
2246
2386
|
@media (max-width: 900px) {
|
|
2247
|
-
.charts-row
|
|
2387
|
+
.charts-row,
|
|
2388
|
+
.charts-row.with-share {
|
|
2248
2389
|
grid-template-columns: 1fr;
|
|
2249
2390
|
}
|
|
2250
2391
|
.cards-row {
|