|
| 1 | +import path from "node:path"; |
| 2 | +import { Command } from "commander"; |
| 3 | +import { generateBenchmarkReport, renderBenchmarkReportMarkdown } from "../../core/report"; |
| 4 | +import { writeTextFile } from "../../utils/fs"; |
| 5 | +import { printKeyValue } from "../../utils/output"; |
| 6 | + |
| 7 | +export function registerReportCommand(program: Command): void { |
| 8 | + program |
| 9 | + .command("report") |
| 10 | + .description("Generate a benchmark-style report for a directory of bundles.") |
| 11 | + .option("--json", "Print machine-readable JSON instead of text") |
| 12 | + .option("--out <file>", "Write a Markdown report to a file") |
| 13 | + .argument("<rootDir>", "Directory that contains bundle folders") |
| 14 | + .action(async (rootDir: string, options: { json?: boolean; out?: string }) => { |
| 15 | + const report = await generateBenchmarkReport(path.resolve(rootDir)); |
| 16 | + |
| 17 | + if (options.out) { |
| 18 | + const markdown = renderBenchmarkReportMarkdown(report); |
| 19 | + await writeTextFile(path.resolve(options.out), markdown); |
| 20 | + } |
| 21 | + |
| 22 | + if (options.json) { |
| 23 | + console.log(JSON.stringify(report, null, 2)); |
| 24 | + return; |
| 25 | + } |
| 26 | + |
| 27 | + console.log("Task Bundle Benchmark Report"); |
| 28 | + console.log("----------------------------"); |
| 29 | + printKeyValue("Root", report.rootDir); |
| 30 | + printKeyValue("Bundles", String(report.bundleCount)); |
| 31 | + printKeyValue("Scored bundles", String(report.scoredBundleCount)); |
| 32 | + printKeyValue("Average score", report.averageScore !== undefined ? Number(report.averageScore.toFixed(4)).toString() : "n/a"); |
| 33 | + console.log(""); |
| 34 | + console.log("Ranking"); |
| 35 | + for (const entry of report.ranking) { |
| 36 | + console.log( |
| 37 | + `${entry.rank}. ${entry.title} | ${entry.tool ?? "unknown"} / ${entry.model ?? "unknown"} | ${ |
| 38 | + entry.status ?? "unknown" |
| 39 | + } | score ${entry.score !== undefined ? Number(entry.score.toFixed(4)).toString() : "n/a"}` |
| 40 | + ); |
| 41 | + } |
| 42 | + console.log(""); |
| 43 | + console.log("Leaderboard"); |
| 44 | + for (const entry of report.leaderboard) { |
| 45 | + console.log( |
| 46 | + `- ${entry.tool ?? "unknown"} / ${entry.model ?? "unknown"} | runs ${entry.runs} | avg ${ |
| 47 | + entry.averageScore !== undefined ? Number(entry.averageScore.toFixed(4)).toString() : "n/a" |
| 48 | + } | best ${entry.bestScore !== undefined ? Number(entry.bestScore.toFixed(4)).toString() : "n/a"}` |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + if (options.out) { |
| 53 | + console.log(""); |
| 54 | + console.log(`Markdown report: ${path.resolve(options.out)}`); |
| 55 | + } |
| 56 | + }); |
| 57 | +} |
0 commit comments