diff --git a/src/compare-stats.ts b/src/compare-stats.ts index 8a177b94..5c938fb1 100644 --- a/src/compare-stats.ts +++ b/src/compare-stats.ts @@ -186,63 +186,64 @@ async function collectJsonlFiles(sessionDir: string): Promise { return files } -export async function scanSelfCorrections(sessionDirs: string[]): Promise> { +export async function scanSelfCorrections(projectDirs: string[]): Promise> { const counts = new Map() - 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 + 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)['type'] !== 'assistant' - ) continue + const msgRec = msg as Record + const model = msgRec['model'] + if (typeof model !== 'string' || model === '') continue - const msg = (parsed as Record)['message'] - if (msg === null || typeof msg !== 'object') continue - - const model = (msg as Record)['model'] - if (typeof model !== 'string' || model === '') continue - - const text = extractText((msg as Record)['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) } } } diff --git a/src/compare.tsx b/src/compare.tsx index d8ae6970..4e78729d 100644 --- a/src/compare.tsx +++ b/src/compare.tsx @@ -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 ( - - {modelA.model} - vs - {modelB.model} - - - - {''.padEnd(LABEL_WIDTH)} - {nameA.padStart(VALUE_WIDTH)} - {nameB.padStart(VALUE_WIDTH)} - - {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 ( - - {row.label.padEnd(LABEL_WIDTH)} - {fmtA.padStart(VALUE_WIDTH)} - {fmtB.padStart(VALUE_WIDTH)} - {winnerLabel.padStart(WINNER_WIDTH)} - - ) - })} - - {'-- Context '.padEnd(LABEL_WIDTH + VALUE_WIDTH * 2 + WINNER_WIDTH, '-')} - {contextRows.map(row => ( - - {row.label.padEnd(LABEL_WIDTH)} - {row.valueA.padStart(VALUE_WIDTH)} - {row.valueB.padStart(VALUE_WIDTH)} + + + {modelA.model} + vs + {modelB.model} - ))} - {(lowDataA || lowDataB) && ( - <> - - - 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. + + + {''.padEnd(LABEL_WIDTH)} + {nameA.padStart(VALUE_WIDTH)} + {nameB.padStart(VALUE_WIDTH)} + + {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 ( + + {row.label.padEnd(LABEL_WIDTH)} + {fmtA.padStart(VALUE_WIDTH)} + {fmtB.padStart(VALUE_WIDTH)} + {' '}{winnerLabel.padEnd(WINNER_WIDTH)} + + ) + })} + + {'-- Context '.padEnd(LABEL_WIDTH + VALUE_WIDTH * 2 + WINNER_WIDTH, '-')} + {contextRows.map(row => ( + + {row.label.padEnd(LABEL_WIDTH)} + {row.valueA.padStart(VALUE_WIDTH)} + {row.valueB.padStart(VALUE_WIDTH)} - - )} + ))} + {(lowDataA || lowDataB) && ( + <> + + + 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. + + + )} + [esc] back