|
| 1 | +#!/usr/bin/env bun |
| 2 | +/** |
| 3 | + * List eval runs from ~/.gstack-dev/evals/ |
| 4 | + * |
| 5 | + * Usage: bun run eval:list [--branch <name>] [--tier e2e|llm-judge] [--limit N] |
| 6 | + */ |
| 7 | + |
| 8 | +import * as fs from 'fs'; |
| 9 | +import * as path from 'path'; |
| 10 | +import * as os from 'os'; |
| 11 | + |
| 12 | +const EVAL_DIR = path.join(os.homedir(), '.gstack-dev', 'evals'); |
| 13 | + |
| 14 | +// Parse args |
| 15 | +const args = process.argv.slice(2); |
| 16 | +let filterBranch: string | null = null; |
| 17 | +let filterTier: string | null = null; |
| 18 | +let limit = 20; |
| 19 | + |
| 20 | +for (let i = 0; i < args.length; i++) { |
| 21 | + if (args[i] === '--branch' && args[i + 1]) { filterBranch = args[++i]; } |
| 22 | + else if (args[i] === '--tier' && args[i + 1]) { filterTier = args[++i]; } |
| 23 | + else if (args[i] === '--limit' && args[i + 1]) { limit = parseInt(args[++i], 10); } |
| 24 | +} |
| 25 | + |
| 26 | +// Read eval files |
| 27 | +let files: string[]; |
| 28 | +try { |
| 29 | + files = fs.readdirSync(EVAL_DIR).filter(f => f.endsWith('.json')); |
| 30 | +} catch { |
| 31 | + console.log('No eval runs yet. Run: EVALS=1 bun run test:evals'); |
| 32 | + process.exit(0); |
| 33 | +} |
| 34 | + |
| 35 | +if (files.length === 0) { |
| 36 | + console.log('No eval runs yet. Run: EVALS=1 bun run test:evals'); |
| 37 | + process.exit(0); |
| 38 | +} |
| 39 | + |
| 40 | +// Parse top-level fields from each file |
| 41 | +interface RunSummary { |
| 42 | + file: string; |
| 43 | + timestamp: string; |
| 44 | + branch: string; |
| 45 | + tier: string; |
| 46 | + version: string; |
| 47 | + passed: number; |
| 48 | + total: number; |
| 49 | + cost: number; |
| 50 | +} |
| 51 | + |
| 52 | +const runs: RunSummary[] = []; |
| 53 | +for (const file of files) { |
| 54 | + try { |
| 55 | + const data = JSON.parse(fs.readFileSync(path.join(EVAL_DIR, file), 'utf-8')); |
| 56 | + if (filterBranch && data.branch !== filterBranch) continue; |
| 57 | + if (filterTier && data.tier !== filterTier) continue; |
| 58 | + runs.push({ |
| 59 | + file, |
| 60 | + timestamp: data.timestamp || '', |
| 61 | + branch: data.branch || 'unknown', |
| 62 | + tier: data.tier || 'unknown', |
| 63 | + version: data.version || '?', |
| 64 | + passed: data.passed || 0, |
| 65 | + total: data.total_tests || 0, |
| 66 | + cost: data.total_cost_usd || 0, |
| 67 | + }); |
| 68 | + } catch { continue; } |
| 69 | +} |
| 70 | + |
| 71 | +// Sort by timestamp descending |
| 72 | +runs.sort((a, b) => b.timestamp.localeCompare(a.timestamp)); |
| 73 | + |
| 74 | +// Apply limit |
| 75 | +const displayed = runs.slice(0, limit); |
| 76 | + |
| 77 | +// Print table |
| 78 | +console.log(''); |
| 79 | +console.log(`Eval History (${runs.length} total runs)`); |
| 80 | +console.log('═'.repeat(90)); |
| 81 | +console.log( |
| 82 | + ' ' + |
| 83 | + 'Date'.padEnd(17) + |
| 84 | + 'Branch'.padEnd(28) + |
| 85 | + 'Tier'.padEnd(12) + |
| 86 | + 'Pass'.padEnd(8) + |
| 87 | + 'Cost'.padEnd(8) + |
| 88 | + 'Version' |
| 89 | +); |
| 90 | +console.log('─'.repeat(90)); |
| 91 | + |
| 92 | +for (const run of displayed) { |
| 93 | + const date = run.timestamp.replace('T', ' ').slice(0, 16); |
| 94 | + const branch = run.branch.length > 26 ? run.branch.slice(0, 23) + '...' : run.branch.padEnd(28); |
| 95 | + const pass = `${run.passed}/${run.total}`.padEnd(8); |
| 96 | + const cost = `$${run.cost.toFixed(2)}`.padEnd(8); |
| 97 | + console.log(` ${date.padEnd(17)}${branch}${run.tier.padEnd(12)}${pass}${cost}v${run.version}`); |
| 98 | +} |
| 99 | + |
| 100 | +console.log('─'.repeat(90)); |
| 101 | + |
| 102 | +const totalCost = runs.reduce((s, r) => s + r.cost, 0); |
| 103 | +console.log(` ${runs.length} runs | Total spend: $${totalCost.toFixed(2)} | Showing: ${displayed.length}`); |
| 104 | +console.log(` Dir: ${EVAL_DIR}`); |
| 105 | +console.log(''); |
0 commit comments