mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
feat(app): Sankey slash-paths + Models "By task" regroup
- Sankey project labels now show the last 2-3 path segments joined by "/" (dropping the users/home prefix) instead of the dash-mangled full path - Models "By task" regrouped CI-style: a per-model group header (series dot + model + aggregate calls/cost/saved) with indented task sub-rows and aligned columns, replacing the flat list that repeated the model name on every row typecheck clean; 128/128 tests pass.
This commit is contained in:
parent
4186ad393a
commit
3f40aeee97
5 changed files with 142 additions and 11 deletions
|
|
@ -152,8 +152,21 @@ function modelDisplayLabel(raw: string): string {
|
|||
function projectDisplayLabel(raw: string): string {
|
||||
const value = raw.trim()
|
||||
if (isOtherNode(value)) return 'Other'
|
||||
const parts = value.split(/[\\/]+/).filter(Boolean)
|
||||
return ellipsize(parts.at(-1) ?? value, 24)
|
||||
const pathDelimited = /[\\/]/.test(value)
|
||||
const parts = value.split(pathDelimited ? /[\\/]+/ : /-+/).filter(Boolean)
|
||||
let displayParts = parts.slice(-3)
|
||||
|
||||
// A three-segment tail rooted directly under a home directory starts with
|
||||
// the user name, which adds noise rather than useful project context.
|
||||
if (displayParts.length === 3 && /^(users?|home)$/i.test(parts.at(-4) ?? '')) {
|
||||
displayParts = displayParts.slice(1)
|
||||
}
|
||||
|
||||
if (/^(projects|src|config)$/i.test(displayParts[0] ?? '')) {
|
||||
displayParts[0] = displayParts[0].toLowerCase()
|
||||
}
|
||||
|
||||
return ellipsize(displayParts.join('/') || value, 24)
|
||||
}
|
||||
|
||||
function shortenId(value: string): string {
|
||||
|
|
|
|||
|
|
@ -100,6 +100,17 @@ const byTaskRows: ModelReportRow[] = [
|
|||
costUSD: 244.12,
|
||||
savingsUSD: 61.22,
|
||||
},
|
||||
{
|
||||
...rows[0],
|
||||
category: 'delegation',
|
||||
calls: 120,
|
||||
inputTokens: 8_000_000,
|
||||
outputTokens: 500_000,
|
||||
cacheReadTokens: 6_000_000,
|
||||
totalTokens: 14_500_000,
|
||||
costUSD: 20.88,
|
||||
savingsUSD: 5.18,
|
||||
},
|
||||
]
|
||||
|
||||
describe('Models', () => {
|
||||
|
|
@ -175,6 +186,13 @@ describe('Models', () => {
|
|||
|
||||
await waitFor(() => expect(getModels).toHaveBeenCalledWith('week', 'anthropic', true))
|
||||
expect(await screen.findByText('coding')).toBeInTheDocument()
|
||||
expect(screen.getByText('delegation')).toBeInTheDocument()
|
||||
expect(screen.getByText('3,520')).toBeInTheDocument()
|
||||
expect(screen.getByText('$265.00')).toBeInTheDocument()
|
||||
expect(screen.getByText('$66.40')).toBeInTheDocument()
|
||||
expect(screen.getByText('$244.12')).toBeInTheDocument()
|
||||
expect(screen.getAllByText('Claude Opus 4.8')).toHaveLength(1)
|
||||
expect(document.querySelectorAll('.model-task-group')).toHaveLength(1)
|
||||
expect(document.querySelectorAll('.model-task-row')).toHaveLength(2)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -83,6 +83,8 @@ export function Models({
|
|||
}
|
||||
|
||||
function ModelsTable({ rows, byTask }: { rows: ModelReportRow[]; byTask: boolean }) {
|
||||
if (byTask) return <ModelsByTaskTable rows={rows} />
|
||||
|
||||
return (
|
||||
<table>
|
||||
<thead>
|
||||
|
|
@ -98,14 +100,42 @@ function ModelsTable({ rows, byTask }: { rows: ModelReportRow[]; byTask: boolean
|
|||
</thead>
|
||||
<tbody>
|
||||
{rows.map((row, i) => (
|
||||
<ModelTableRow key={`${row.provider}-${row.model}-${row.category ?? 'all'}-${i}`} row={row} byTask={byTask} />
|
||||
<ModelTableRow key={`${row.provider}-${row.model}-${i}`} row={row} />
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)
|
||||
}
|
||||
|
||||
function ModelTableRow({ row, byTask }: { row: ModelReportRow; byTask: boolean }) {
|
||||
function ModelsByTaskTable({ rows }: { rows: ModelReportRow[] }) {
|
||||
const groups = groupTaskRows(rows)
|
||||
|
||||
return (
|
||||
<table className="models-by-task">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Task</th>
|
||||
<th>Calls</th>
|
||||
<th>Input</th>
|
||||
<th>Output</th>
|
||||
<th>Cache read</th>
|
||||
<th>Cost</th>
|
||||
<th>Saved</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{groups.map(group => (
|
||||
<tbody className="model-task-group" key={`${group.provider}-${group.model}`}>
|
||||
<ModelGroupRow rows={group.rows} />
|
||||
{group.rows.map((row, i) => (
|
||||
<ModelTaskRow key={`${row.category ?? 'all'}-${i}`} row={row} />
|
||||
))}
|
||||
</tbody>
|
||||
))}
|
||||
</table>
|
||||
)
|
||||
}
|
||||
|
||||
function ModelTableRow({ row }: { row: ModelReportRow }) {
|
||||
const unpriced = row.costUSD === 0 && row.savingsUSD === 0
|
||||
const cellClass = unpriced ? 'dim' : undefined
|
||||
const tokenValue = (value: number) => (unpriced ? '—' : fmtCompact(value))
|
||||
|
|
@ -120,12 +150,6 @@ function ModelTableRow({ row, byTask }: { row: ModelReportRow; byTask: boolean }
|
|||
<td className={cellClass} title={row.model}>
|
||||
<span className="mdot" style={dotStyle} />
|
||||
{row.modelDisplayName}
|
||||
{byTask && row.category ? (
|
||||
<>
|
||||
{' · '}
|
||||
<span className="est">{row.category}</span>
|
||||
</>
|
||||
) : null}
|
||||
{unpriced ? (
|
||||
<>
|
||||
{' '}
|
||||
|
|
@ -142,3 +166,61 @@ function ModelTableRow({ row, byTask }: { row: ModelReportRow; byTask: boolean }
|
|||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
function ModelGroupRow({ rows }: { rows: ModelReportRow[] }) {
|
||||
const model = rows[0]
|
||||
const calls = rows.reduce((sum, row) => sum + row.calls, 0)
|
||||
const costUSD = rows.reduce((sum, row) => sum + row.costUSD, 0)
|
||||
const savingsUSD = rows.reduce((sum, row) => sum + row.savingsUSD, 0)
|
||||
const unpriced = costUSD === 0 && savingsUSD === 0
|
||||
|
||||
return (
|
||||
<tr className="model-group-row">
|
||||
<td className={unpriced ? 'dim' : undefined} title={model.model}>
|
||||
<span className="model-group-lead">
|
||||
<span
|
||||
className="mdot"
|
||||
style={{ background: seriesColorForModel(model.modelDisplayName || model.model) }}
|
||||
/>
|
||||
<span className="model-group-name">{model.modelDisplayName}</span>
|
||||
{unpriced ? <span className="alias">add alias ›</span> : null}
|
||||
</span>
|
||||
</td>
|
||||
<td className={unpriced ? 'dim' : undefined}>{fmtInt(calls)}</td>
|
||||
<td aria-label="No aggregate input" />
|
||||
<td aria-label="No aggregate output" />
|
||||
<td aria-label="No aggregate cache read" />
|
||||
<td className={unpriced ? 'dim' : undefined}>{unpriced ? '—' : formatUsd(costUSD)}</td>
|
||||
<td className={unpriced ? 'dim' : savingsUSD > 0 ? 'pos' : undefined}>{unpriced ? '—' : formatUsd(savingsUSD)}</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
function ModelTaskRow({ row }: { row: ModelReportRow }) {
|
||||
const unpriced = row.costUSD === 0 && row.savingsUSD === 0
|
||||
const cellClass = unpriced ? 'dim' : undefined
|
||||
const tokenValue = (value: number) => (unpriced ? '—' : fmtCompact(value))
|
||||
|
||||
return (
|
||||
<tr className="model-task-row">
|
||||
<td className={cellClass}>{row.category ?? 'general'}</td>
|
||||
<td className={cellClass}>{fmtInt(row.calls)}</td>
|
||||
<td className={cellClass}>{tokenValue(row.inputTokens)}</td>
|
||||
<td className={cellClass}>{tokenValue(row.outputTokens)}</td>
|
||||
<td className={cellClass}>{tokenValue(row.cacheReadTokens)}</td>
|
||||
<td className={cellClass}>{unpriced ? '—' : formatUsd(row.costUSD)}</td>
|
||||
<td className={unpriced ? 'dim' : row.savingsUSD > 0 ? 'pos' : undefined}>{unpriced ? '—' : formatUsd(row.savingsUSD)}</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
function groupTaskRows(rows: ModelReportRow[]) {
|
||||
const groups = new Map<string, { provider: string; model: string; rows: ModelReportRow[] }>()
|
||||
for (const row of rows) {
|
||||
const key = `${row.provider}\u0000${row.model}`
|
||||
const group = groups.get(key)
|
||||
if (group) group.rows.push(row)
|
||||
else groups.set(key, { provider: row.provider, model: row.model, rows: [row] })
|
||||
}
|
||||
return [...groups.values()]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ describe('Spend', () => {
|
|||
expect(screen.getByText(/gpt-5.5-codex/)).toBeInTheDocument()
|
||||
expect(screen.queryByText(/Opus 4.8/)).not.toBeInTheDocument()
|
||||
expect(screen.queryByText(/GPT-5.5 Codex/)).not.toBeInTheDocument()
|
||||
expect(screen.getByText(/mobile-app/)).toBeInTheDocument()
|
||||
expect(screen.getByText(/src\/mobile-app/)).toBeInTheDocument()
|
||||
expect(screen.queryByText(/Users\/me\/src\/mobile-app/)).not.toBeInTheDocument()
|
||||
|
||||
const opusRibbon = container.querySelector('[data-testid="sankey-ribbon"][data-model="claude-opus-4-20260701"]')
|
||||
|
|
|
|||
|
|
@ -291,6 +291,24 @@ body { overflow: hidden; background: var(--bg); color: var(--ink); }
|
|||
.phead { border-color: var(--line2); }
|
||||
.phead .r.link, a { color: var(--accent); }
|
||||
.alias { color: var(--accent); }
|
||||
|
||||
/* Models: grouped task lens. */
|
||||
.models-by-task { min-width: 660px; }
|
||||
.models-by-task .model-task-group + .model-task-group { border-top: 1px solid var(--line2); }
|
||||
.models-by-task .model-group-row td {
|
||||
padding-top: 10px; padding-bottom: 10px; border-bottom: 0; background: var(--phead);
|
||||
color: var(--ink); font-weight: 560;
|
||||
}
|
||||
.models-by-task .model-group-lead { display: flex; align-items: center; gap: 9px; }
|
||||
.models-by-task .model-group-row .mdot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
|
||||
.models-by-task .model-group-name { font-size: 13px; font-weight: 600; }
|
||||
.models-by-task .model-task-row td { position: relative; border-bottom: 0; }
|
||||
.models-by-task .model-task-row td::before {
|
||||
content: ''; position: absolute; top: 0; right: 0; left: 0; height: 1px; background: var(--line2);
|
||||
}
|
||||
.models-by-task .model-task-row td:first-child { padding-left: 24px; font-weight: 500; }
|
||||
.models-by-task .model-task-row td:first-child::before { left: 22px; }
|
||||
.models-by-task .model-task-row td:last-child::before { right: 2px; }
|
||||
.bars .b, .bars .c.hi .b, .bars .c.hi2 .b { background: var(--bar); box-shadow: none; }
|
||||
.bars .c.hi .b { background: var(--bar-hi); }
|
||||
.bars .c.hi2 .b { background: color-mix(in srgb, var(--bar-hi) 70%, var(--bar)); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue