mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
fix(dash): lead the session legend with the session title
Grouping the hourly chart by session labelled every series with the project path plus a truncated session id. In a monorepo every series shares that prefix, so the legend reads as half a dozen indistinguishable hex fragments — and telling one application's spend from another is the main reason to open that chart in the first place. The title is already there: SessionSummary.title is parsed from the transcript and the Context tab already displays it. The legend now prefers it, keeps the short id as the suffix so two sessions sharing a title stay distinguishable, and falls back to the existing project label when a session has no title. Titles come from transcripts, so they get the same treatment as model names: ANSI stripped, control characters flattened to spaces, whitespace collapsed, and a length cap so a 200-character title cannot dominate the legend or the tooltip. The label is built once per session rather than per API call, since every input to it is constant for a given series key. Reported in #997. The clickable-legend half of that issue is not included.
This commit is contained in:
parent
da3d903887
commit
e013f78d78
3 changed files with 95 additions and 2 deletions
|
|
@ -15,6 +15,7 @@
|
|||
- **The resident `codeburn serve` child.** The first real panel request is also the cache warm-up, so startup never runs an artificial warm-up query beside a duplicate one-shot child; each served command carries its own read-only option allowlist, and anything outside it falls back to a normal spawn; the child exits when its stdin closes, so it can never outlive the app. Requests whose response exceeds the 16 MiB frame limit still replace the child, but that deliberate kill no longer spends the resident's unexpected-death budget. (#972)
|
||||
|
||||
### Fixed
|
||||
- **The session chart legend now leads with the session title instead of the project path.** Every series in a monorepo shared the same project prefix, so the only thing separating them was a truncated hex fragment — and per-application cost attribution is the main reason to open that chart. `SessionSummary.title` is already parsed and already rendered in the Context tab; the legend now prefers it, keeps the short session id as the disambiguator for sessions that share a title, and falls back to the previous project-based label when a session never produced one. Titles come from transcripts, so they are stripped of ANSI and control characters and capped before they reach either the legend or the tooltip. (#997)
|
||||
- **Bash command splitting was quadratic on long whitespace-heavy commands.** The separator regex retried its leading `\s*` from every offset; matching the separator alone and widening over whitespace by hand makes cold parse ~24% and warm ~40% faster on large corpora, output unchanged.
|
||||
- **Cold parse no longer retains full message bodies through cached previews.** `flatSlice` skipped its Buffer round-trip for strings already within the bound, but provider adapters pre-truncate user-message previews with `.slice(0, 500)` before the cache-site call — those pre-sliced views are still V8 SlicedStrings pinning their large parent, so the retention that OOM'd cold parses of large histories survived. The round-trip now always runs.
|
||||
- **Kiro sessions carry the real `projectPath`** (CLI meta.cwd, v2 `workspacePaths[0]`, workspace sessions' `workspaceDirectory`), so git-repo attribution can resolve them; previously they were attribution-blind. Bumps the kiro parse version, so the first run after upgrade re-parses kiro history once, and kiro sessions in linked git worktrees now group under the main repo.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import stripAnsi from 'strip-ansi'
|
||||
|
||||
import type { DateRange, ProjectSummary } from './types.js'
|
||||
|
||||
const FIFTEEN_MINUTES = 15
|
||||
|
|
@ -5,6 +7,10 @@ const ONE_HOUR = 60
|
|||
const ONE_DAY = 24 * 60
|
||||
const MINUTE_MS = 60 * 1000
|
||||
const MAX_SERIES_PER_METRIC = 6
|
||||
// Keep metadata bounded for both the max-w-40 legend and the tooltip: 80
|
||||
// characters preserves a useful title without letting the parser's 200-char
|
||||
// transcript cap dominate either UI surface.
|
||||
const MAX_SESSION_TITLE_LENGTH = 80
|
||||
|
||||
export type GranularSeries = {
|
||||
id: string
|
||||
|
|
@ -99,6 +105,21 @@ function shortSessionId(sessionId: string): string {
|
|||
return trimmed.length > 12 ? `${trimmed.slice(0, 6)}…${trimmed.slice(-4)}` : trimmed || 'unknown'
|
||||
}
|
||||
|
||||
function cleanSessionTitle(title: string | undefined): string | undefined {
|
||||
if (title === undefined) return undefined
|
||||
|
||||
// Match the control-character range used by the model-name sanitizer. ANSI
|
||||
// sequences are removed first; remaining controls become spaces so transcript
|
||||
// line breaks cannot join words before internal whitespace is collapsed.
|
||||
const cleaned = stripAnsi(title)
|
||||
.replace(/[\x00-\x1F\x7F-\x9F]/g, ' ')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim()
|
||||
if (!cleaned) return undefined
|
||||
|
||||
return cleaned.slice(0, MAX_SESSION_TITLE_LENGTH).trimEnd() || undefined
|
||||
}
|
||||
|
||||
// Legend labels: the sanitized project dir ("-Users-name-Projects-app") is
|
||||
// unreadable, so prefer the real projectPath's last two segments ("app/web").
|
||||
// Fall back to the sanitized name when no usable path exists.
|
||||
|
|
@ -214,7 +235,13 @@ export function buildGranularHistory(
|
|||
add(modelTotals, modelKey, cost, tokens)
|
||||
add(sessionTotals, sessionKey, cost, tokens)
|
||||
modelLabels.set(modelKey, modelKey === '<synthetic>' ? 'Other model' : modelKey)
|
||||
sessionLabels.set(sessionKey, `${shortProjectLabel(project.projectPath, projectName)} · ${shortSessionId(session.sessionId)} (${call.provider})`)
|
||||
// Every input is constant for a given sessionKey (the provider is part
|
||||
// of the key), so build the label once instead of re-sanitizing the
|
||||
// title on every call in the session.
|
||||
if (!sessionLabels.has(sessionKey)) {
|
||||
const sessionLabel = cleanSessionTitle(session.title) ?? shortProjectLabel(project.projectPath, projectName)
|
||||
sessionLabels.set(sessionKey, `${sessionLabel} · ${shortSessionId(session.sessionId)} (${call.provider})`)
|
||||
}
|
||||
callCount++
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ function apiCall(options: {
|
|||
}
|
||||
}
|
||||
|
||||
function project(sessions: Array<{ id: string; project?: string; calls: ParsedApiCall[] }>): ProjectSummary {
|
||||
function project(sessions: Array<{ id: string; project?: string; title?: string; calls: ParsedApiCall[] }>): ProjectSummary {
|
||||
return {
|
||||
project: 'demo',
|
||||
projectPath: '/repos/demo',
|
||||
|
|
@ -56,6 +56,7 @@ function project(sessions: Array<{ id: string; project?: string; calls: ParsedAp
|
|||
sessions: sessions.map(session => ({
|
||||
sessionId: session.id,
|
||||
project: session.project ?? 'demo',
|
||||
title: session.title,
|
||||
firstTimestamp: session.calls[0]?.timestamp ?? '',
|
||||
lastTimestamp: session.calls.at(-1)?.timestamp ?? '',
|
||||
totalCostUSD: session.calls.reduce((sum, call) => sum + call.costUSD, 0),
|
||||
|
|
@ -107,6 +108,70 @@ describe('granular history', () => {
|
|||
expect(granularBucketMinutes(range(24 * 30))).toBe(1440)
|
||||
})
|
||||
|
||||
it('prefers a sanitised session title and preserves the exact project fallback when it is missing or blank', () => {
|
||||
const timestamp = '2026-07-15T12:05:00.000Z'
|
||||
const start = new Date('2026-07-15T00:00:00.000Z')
|
||||
const end = new Date('2026-07-15T23:59:59.999Z')
|
||||
const history = buildGranularHistory([project([
|
||||
{ id: 'session-titled-123456', title: 'Refactor billing module', calls: [apiCall({ timestamp, cost: 1 })] },
|
||||
{ id: 'session-absent-123457', calls: [apiCall({ timestamp, cost: 1 })] },
|
||||
{ id: 'session-empty-123458', title: '', calls: [apiCall({ timestamp, cost: 1 })] },
|
||||
{ id: 'session-blank-123459', title: ' \t\n ', calls: [apiCall({ timestamp, cost: 1 })] },
|
||||
])], { start, end }, end)
|
||||
|
||||
expect(history.sessionSeries.map(series => series.label)).toEqual([
|
||||
'Refactor billing module · sessio…3456 (claude)',
|
||||
'repos/demo · sessio…3457 (claude)',
|
||||
'repos/demo · sessio…3458 (claude)',
|
||||
'repos/demo · sessio…3459 (claude)',
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps identical session titles distinguishable with the short session id', () => {
|
||||
const timestamp = '2026-07-15T12:05:00.000Z'
|
||||
const start = new Date('2026-07-15T00:00:00.000Z')
|
||||
const end = new Date('2026-07-15T23:59:59.999Z')
|
||||
const history = buildGranularHistory([project([
|
||||
{ id: 'session-111111', title: 'Refactor billing module', calls: [apiCall({ timestamp, cost: 1 })] },
|
||||
{ id: 'session-222222', title: 'Refactor billing module', calls: [apiCall({ timestamp, cost: 1 })] },
|
||||
])], { start, end }, end)
|
||||
|
||||
expect(history.sessionSeries.map(series => series.id)).toEqual(['session_0', 'session_1'])
|
||||
expect(history.sessionSeries.map(series => series.label)).toEqual([
|
||||
'Refactor billing module · sessio…1111 (claude)',
|
||||
'Refactor billing module · sessio…2222 (claude)',
|
||||
])
|
||||
expect(new Set(history.sessionSeries.map(series => series.label)).size).toBe(2)
|
||||
})
|
||||
|
||||
it('sanitises control characters and ANSI escapes in session titles', () => {
|
||||
const timestamp = '2026-07-15T12:05:00.000Z'
|
||||
const start = new Date('2026-07-15T00:00:00.000Z')
|
||||
const end = new Date('2026-07-15T23:59:59.999Z')
|
||||
const history = buildGranularHistory([project([{
|
||||
id: 'session-sanitised-123456',
|
||||
title: '\x1b[31mRefactor\x1b[0m\t billing\nmodule\x00',
|
||||
calls: [apiCall({ timestamp, cost: 1 })],
|
||||
}])], { start, end }, end)
|
||||
|
||||
expect(history.sessionSeries[0]?.label).toBe('Refactor billing module · sessio…3456 (claude)')
|
||||
expect(history.sessionSeries[0]?.label).not.toContain('\x1b')
|
||||
expect(history.sessionSeries[0]?.label).not.toContain('\x00')
|
||||
})
|
||||
|
||||
it('caps over-long session titles before putting them in the legend label', () => {
|
||||
const timestamp = '2026-07-15T12:05:00.000Z'
|
||||
const start = new Date('2026-07-15T00:00:00.000Z')
|
||||
const end = new Date('2026-07-15T23:59:59.999Z')
|
||||
const history = buildGranularHistory([project([{
|
||||
id: 'session-long-title-123456',
|
||||
title: 'x'.repeat(200),
|
||||
calls: [apiCall({ timestamp, cost: 1 })],
|
||||
}])], { start, end }, end)
|
||||
|
||||
expect(history.sessionSeries[0]?.label).toBe('x'.repeat(80) + ' · sessio…3456 (claude)')
|
||||
})
|
||||
|
||||
it('fills idle buckets and keeps separate model and session lines from real call timestamps', () => {
|
||||
const start = new Date('2026-07-15T00:00:00.000Z')
|
||||
const end = new Date('2026-07-15T23:59:59.999Z')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue