mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 02:39:13 +00:00
fix(compare): scan project-level JSONL files, improve results layout
Self-correction scanner was only reading JSONL files inside session subdirectories, missing the main session transcripts stored at the project level. Also adds bordered box to results and widens winner column for readability.
This commit is contained in:
parent
d3864914a9
commit
d52a55afb4
2 changed files with 82 additions and 79 deletions
|
|
@ -186,63 +186,64 @@ async function collectJsonlFiles(sessionDir: string): Promise<string[]> {
|
|||
return files
|
||||
}
|
||||
|
||||
export async function scanSelfCorrections(sessionDirs: string[]): Promise<Map<string, number>> {
|
||||
export async function scanSelfCorrections(projectDirs: string[]): Promise<Map<string, number>> {
|
||||
const counts = new Map<string, number>()
|
||||
|
||||
for (const dir of sessionDirs) {
|
||||
let sessionEntries
|
||||
for (const dir of projectDirs) {
|
||||
let entries
|
||||
try {
|
||||
sessionEntries = await readdir(dir, { withFileTypes: true })
|
||||
entries = await readdir(dir, { withFileTypes: true })
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
|
||||
for (const entry of sessionEntries) {
|
||||
if (!entry.isDirectory()) continue
|
||||
const sessionDir = join(dir, entry.name)
|
||||
const allFiles: string[] = []
|
||||
|
||||
let files: string[]
|
||||
for (const entry of entries) {
|
||||
if (entry.isFile() && entry.name.endsWith('.jsonl')) {
|
||||
allFiles.push(join(dir, entry.name))
|
||||
} else if (entry.isDirectory()) {
|
||||
try {
|
||||
const sessionFiles = await collectJsonlFiles(join(dir, entry.name))
|
||||
allFiles.push(...sessionFiles)
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const file of allFiles) {
|
||||
let raw: string
|
||||
try {
|
||||
files = await collectJsonlFiles(sessionDir)
|
||||
raw = await readFile(file, 'utf8')
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
let raw: string
|
||||
for (const line of raw.split('\n')) {
|
||||
const trimmed = line.trim()
|
||||
if (!trimmed) continue
|
||||
|
||||
let parsed: unknown
|
||||
try {
|
||||
raw = await readFile(file, 'utf8')
|
||||
parsed = JSON.parse(trimmed)
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
|
||||
for (const line of raw.split('\n')) {
|
||||
const trimmed = line.trim()
|
||||
if (!trimmed) continue
|
||||
const rec = parsed as Record<string, unknown>
|
||||
if (!rec || typeof rec !== 'object' || rec['type'] !== 'assistant') continue
|
||||
|
||||
let parsed: unknown
|
||||
try {
|
||||
parsed = JSON.parse(trimmed)
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
const msg = rec['message']
|
||||
if (msg === null || typeof msg !== 'object') continue
|
||||
|
||||
if (
|
||||
parsed === null ||
|
||||
typeof parsed !== 'object' ||
|
||||
(parsed as Record<string, unknown>)['type'] !== 'assistant'
|
||||
) continue
|
||||
const msgRec = msg as Record<string, unknown>
|
||||
const model = msgRec['model']
|
||||
if (typeof model !== 'string' || model === '<synthetic>') continue
|
||||
|
||||
const msg = (parsed as Record<string, unknown>)['message']
|
||||
if (msg === null || typeof msg !== 'object') continue
|
||||
|
||||
const model = (msg as Record<string, unknown>)['model']
|
||||
if (typeof model !== 'string' || model === '<synthetic>') continue
|
||||
|
||||
const text = extractText((msg as Record<string, unknown>)['content'])
|
||||
if (SELF_CORRECTION_PATTERNS.some(p => p.test(text))) {
|
||||
counts.set(model, (counts.get(model) ?? 0) + 1)
|
||||
}
|
||||
const text = extractText(msgRec['content'])
|
||||
if (SELF_CORRECTION_PATTERNS.some(p => p.test(text))) {
|
||||
counts.set(model, (counts.get(model) ?? 0) + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const GOLD = '#FFD700'
|
|||
const LOW_DATA_THRESHOLD = 20
|
||||
const LABEL_WIDTH = 20
|
||||
const VALUE_WIDTH = 14
|
||||
const WINNER_WIDTH = 12
|
||||
const WINNER_WIDTH = 16
|
||||
const MODEL_NAME_COL = 24
|
||||
const MS_PER_DAY = 24 * 60 * 60 * 1000
|
||||
|
||||
|
|
@ -145,50 +145,52 @@ function ComparisonResults({ modelA, modelB, rows, onBack }: ComparisonResultsPr
|
|||
|
||||
return (
|
||||
<Box flexDirection="column" paddingX={2} paddingY={1}>
|
||||
<Text>
|
||||
<Text bold color={ORANGE}>{modelA.model}</Text>
|
||||
<Text dimColor> vs </Text>
|
||||
<Text bold color={ORANGE}>{modelB.model}</Text>
|
||||
</Text>
|
||||
<Text> </Text>
|
||||
<Text>
|
||||
<Text>{''.padEnd(LABEL_WIDTH)}</Text>
|
||||
<Text bold>{nameA.padStart(VALUE_WIDTH)}</Text>
|
||||
<Text bold>{nameB.padStart(VALUE_WIDTH)}</Text>
|
||||
</Text>
|
||||
{rows.map(row => {
|
||||
const fmtA = formatValue(row.valueA, row.formatFn)
|
||||
const fmtB = formatValue(row.valueB, row.formatFn)
|
||||
const winnerLabel = row.winner === 'a' ? `${nameA} wins`
|
||||
: row.winner === 'b' ? `${nameB} wins`
|
||||
: row.winner === 'tie' ? 'tie' : ''
|
||||
|
||||
return (
|
||||
<Text key={row.label}>
|
||||
<Text dimColor>{row.label.padEnd(LABEL_WIDTH)}</Text>
|
||||
<Text color={row.winner === 'a' ? GREEN : undefined}>{fmtA.padStart(VALUE_WIDTH)}</Text>
|
||||
<Text color={row.winner === 'b' ? GREEN : undefined}>{fmtB.padStart(VALUE_WIDTH)}</Text>
|
||||
<Text color={DIM}>{winnerLabel.padStart(WINNER_WIDTH)}</Text>
|
||||
</Text>
|
||||
)
|
||||
})}
|
||||
<Text> </Text>
|
||||
<Text dimColor>{'-- Context '.padEnd(LABEL_WIDTH + VALUE_WIDTH * 2 + WINNER_WIDTH, '-')}</Text>
|
||||
{contextRows.map(row => (
|
||||
<Text key={row.label}>
|
||||
<Text color={DIM}>{row.label.padEnd(LABEL_WIDTH)}</Text>
|
||||
<Text color={DIM}>{row.valueA.padStart(VALUE_WIDTH)}</Text>
|
||||
<Text color={DIM}>{row.valueB.padStart(VALUE_WIDTH)}</Text>
|
||||
<Box flexDirection="column" borderStyle="round" borderColor={ORANGE} paddingX={1}>
|
||||
<Text>
|
||||
<Text bold color={ORANGE}>{modelA.model}</Text>
|
||||
<Text dimColor> vs </Text>
|
||||
<Text bold color={ORANGE}>{modelB.model}</Text>
|
||||
</Text>
|
||||
))}
|
||||
{(lowDataA || lowDataB) && (
|
||||
<>
|
||||
<Text> </Text>
|
||||
<Text color={GOLD}>
|
||||
Note: {[lowDataA && modelA.model, lowDataB && modelB.model].filter(Boolean).join(' and ')} ha{lowDataA && lowDataB ? 've' : 's'} fewer than {LOW_DATA_THRESHOLD} calls -- results may not be representative.
|
||||
<Text> </Text>
|
||||
<Text>
|
||||
<Text>{''.padEnd(LABEL_WIDTH)}</Text>
|
||||
<Text bold>{nameA.padStart(VALUE_WIDTH)}</Text>
|
||||
<Text bold>{nameB.padStart(VALUE_WIDTH)}</Text>
|
||||
</Text>
|
||||
{rows.map(row => {
|
||||
const fmtA = formatValue(row.valueA, row.formatFn)
|
||||
const fmtB = formatValue(row.valueB, row.formatFn)
|
||||
const winnerLabel = row.winner === 'a' ? `${nameA} wins`
|
||||
: row.winner === 'b' ? `${nameB} wins`
|
||||
: row.winner === 'tie' ? 'tie' : ''
|
||||
|
||||
return (
|
||||
<Text key={row.label}>
|
||||
<Text dimColor>{row.label.padEnd(LABEL_WIDTH)}</Text>
|
||||
<Text color={row.winner === 'a' ? GREEN : undefined}>{fmtA.padStart(VALUE_WIDTH)}</Text>
|
||||
<Text color={row.winner === 'b' ? GREEN : undefined}>{fmtB.padStart(VALUE_WIDTH)}</Text>
|
||||
<Text color={DIM}>{' '}{winnerLabel.padEnd(WINNER_WIDTH)}</Text>
|
||||
</Text>
|
||||
)
|
||||
})}
|
||||
<Text> </Text>
|
||||
<Text dimColor>{'-- Context '.padEnd(LABEL_WIDTH + VALUE_WIDTH * 2 + WINNER_WIDTH, '-')}</Text>
|
||||
{contextRows.map(row => (
|
||||
<Text key={row.label}>
|
||||
<Text color={DIM}>{row.label.padEnd(LABEL_WIDTH)}</Text>
|
||||
<Text color={DIM}>{row.valueA.padStart(VALUE_WIDTH)}</Text>
|
||||
<Text color={DIM}>{row.valueB.padStart(VALUE_WIDTH)}</Text>
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
))}
|
||||
{(lowDataA || lowDataB) && (
|
||||
<>
|
||||
<Text> </Text>
|
||||
<Text color={GOLD}>
|
||||
Note: {[lowDataA && modelA.model, lowDataB && modelB.model].filter(Boolean).join(' and ')} ha{lowDataA && lowDataB ? 've' : 's'} fewer than {LOW_DATA_THRESHOLD} calls -- results may not be representative.
|
||||
</Text>
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
<Text> </Text>
|
||||
<Text>
|
||||
<Text color={ORANGE} bold>[esc]</Text><Text dimColor> back </Text>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue