#!/usr/bin/env node import { Command } from "commander"; import { loadConfigFile, type AgentSkillsEvalConfig } from "./config.js"; import { consoleReporter } from "./console-reporter.js"; import { evaluateSkills } from "./evaluate-skills.js"; import { jsonlReporter, type JsonlReporter } from "./jsonl-reporter.js"; import { OpenAICompatibleProvider } from "./openai-compatible-provider.js"; interface CliOptions { config?: string; workspace?: string; baseline?: boolean; target?: string; judge?: string; baseUrl?: string; apiKeyEnv?: string; include?: string[]; exclude?: string[]; evalId?: string[]; concurrency?: string; report?: boolean; color?: boolean; verbose?: boolean; layout?: "iteration" | "flat"; strict?: boolean; logFormat?: "pretty" | "jsonl" | "silent"; logFile?: string; reportTitle?: string; reportOutput?: string; } function list(value: string, previous: string[] = []): string[] { return [...previous, value]; } function reportEnabled(report: AgentSkillsEvalConfig["report"]): boolean | undefined { if (report === undefined) return undefined; if (typeof report === "boolean") return report; return report.enabled; } function reportTitle(report: AgentSkillsEvalConfig["report"]): string | undefined { return typeof report === "object" && report ? report.title : undefined; } function reportOutput(report: AgentSkillsEvalConfig["report"]): string | undefined { return typeof report === "object" && report ? report.output : undefined; } async function main(): Promise { const program = new Command(); program .name("agent-skills-eval") .description("Evaluate agentskills.io-style skills and write portable benchmark artifacts") .argument("[root]", "Directory to scan for SKILL.md files", ".") .option("--config ", "YAML or JSON config file") .option("--workspace ", "Workspace directory for artifacts") .option("--baseline", "Run both with_skill and without_skill modes") .option("--target ", "Target model name") .option("--judge ", "Judge model name; defaults to --target") .option("--base-url ", "OpenAI-compatible API base URL") .option("--api-key-env ", "Environment variable containing the API key") .option("--include ", "Include skill relPath glob", list, []) .option("--exclude ", "Exclude skill relPath glob", list, []) .option("--eval-id ", "Run only eval cases with this id", list, []) .option("--concurrency ", "Eval cases to run in parallel") .option("--report", "Generate the static HTML report") .option("--no-report", "Skip HTML report generation") .option("--no-color", "Disable ANSI color") .option("--verbose", "Print full prompts, outputs, and judge prompts") .option("--layout ", "Artifact layout: iteration or flat") .option("--strict", "Validate SKILL.md against agentskills.io before running") .option("--log-format ", "Logging format: pretty, jsonl, or silent") .option("--log-file ", "Write JSONL event logs to a file") .option("--report-title ", "HTML report title") .option("--report-output <path>", "HTML report output directory"); program.parse(process.argv); const opts = program.opts<CliOptions>(); const config = opts.config ? loadConfigFile(opts.config) : {}; const root = program.args[0] !== undefined && program.args[0] !== "." ? program.args[0] : config.root ?? "."; const workspace = opts.workspace ?? config.workspace ?? "./agent-skills-workspace"; const targetModel = opts.target ?? config.target ?? "gpt-4o-mini"; const judgeModel = opts.judge ?? config.judge ?? targetModel; const apiKeyEnv = opts.apiKeyEnv ?? config.apiKeyEnv ?? "OPENAI_API_KEY"; const baseUrl = opts.baseUrl ?? config.baseUrl ?? process.env.OPENAI_BASE_URL; const apiKey = process.env[apiKeyEnv]; const include = opts.include && opts.include.length > 0 ? opts.include : config.include; const exclude = opts.exclude && opts.exclude.length > 0 ? opts.exclude : config.exclude; const evalIds = opts.evalId && opts.evalId.length > 0 ? opts.evalId : config.evalIds; const concurrency = opts.concurrency !== undefined ? Number.parseInt(opts.concurrency, 10) : config.concurrency ?? 4; const layout = opts.layout ?? config.layout ?? "iteration"; const strict = opts.strict ?? config.strict ?? false; const enabledReport = opts.report ?? reportEnabled(config.report) ?? true; const title = opts.reportTitle ?? reportTitle(config.report); const output = opts.reportOutput ?? reportOutput(config.report); const logFormat = opts.logFormat ?? config.logging?.format ?? "pretty"; const logFile = opts.logFile ?? config.logging?.file; const verbose = opts.verbose ?? config.logging?.verbose ?? false; const color = opts.color ?? config.logging?.color ?? "auto"; if (!baseUrl) { throw new Error("provide --base-url or set OPENAI_BASE_URL"); } if (!apiKey) { throw new Error(`environment variable ${apiKeyEnv} is not set`); } if (layout !== "iteration" && layout !== "flat") { throw new Error('--layout must be "iteration" or "flat"'); } if (!Number.isInteger(concurrency) || concurrency < 1) { throw new Error("--concurrency must be a positive integer"); } if (logFormat !== "pretty" && logFormat !== "jsonl" && logFormat !== "silent") { throw new Error('--log-format must be "pretty", "jsonl", or "silent"'); } const target = new OpenAICompatibleProvider({ providerName: "openai-compatible", baseUrl, apiKey, model: targetModel, }); const judge = new OpenAICompatibleProvider({ providerName: "openai-compatible", baseUrl, apiKey, model: judgeModel, }); let closeReporter: (() => Promise<void>) | undefined; let onEvent; if (logFormat === "pretty") { onEvent = consoleReporter({ color, verbose, snippetLength: config.logging?.snippetLength, }); } else if (logFormat === "jsonl") { const reporter: JsonlReporter = jsonlReporter({ file: logFile }); onEvent = reporter.onEvent; closeReporter = reporter.close; } else { onEvent = () => undefined; } try { const result = await evaluateSkills({ root, workspace, baseline: opts.baseline ?? config.baseline ?? false, target: { model: targetModel, provider: target }, judge: { model: judgeModel, provider: judge }, include, exclude, evalIds, concurrency, report: enabledReport, reportTitle: title, reportOutput: output, workspaceLayout: layout, strict, targetParams: config.targetParams, judgeParams: config.judgeParams, onEvent, }); process.stdout.write(`${JSON.stringify(result, null, 2)}\n`); process.exitCode = result.failed > 0 ? 1 : 0; } finally { await closeReporter?.(); } } main().catch((err) => { process.stderr.write(`error: ${err instanceof Error ? err.message : String(err)}\n`); process.exitCode = 1; });