/**
 * pr-comment command — generate a PR comment from evaluation scores.
 *
 * Uses the composition root to wire adapters, then calls
 * generatePrComment() directly from pipeline/.
 */
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";
import { Command } from "commander";
import { createAppContext } from "../composition-root.js";
import { generatePrComment } from "../pipeline/pr-comment.js";
import { addOutputDirOption } from "./shared/options.js";
import { resolveOutputDir } from "./shared/resolve-output-dir.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = resolve(__dirname, "..", "..");
export function createPrCommentCommand() {
    const cmd = new Command("pr-comment")
        .description("Generate a markdown PR comment from evaluation scores")
        .option("-o, --output <path>", "Write comment to file (default: stdout)")
        .option("--promptfoo-url <url>", "Promptfoo share URL to include")
        .action(async (opts) => {
        try {
            const ctx = createAppContext({
                rootDir: ROOT,
                outputDir: resolveOutputDir(opts.outputDir),
                mode: "literacy",
                noAutoScope: false,
                skipFetch: true,
                skipEval: true,
                compareEnabled: false,
                gapAnalysisEnabled: false,
                publishEnabled: false,
                noCache: true,
                noRemoteCache: true,
                searchMode: "open",
                remote: false,
                apiUrl: "https://ailf-api.sanity.build",
            });
            generatePrComment({
                outputPath: opts.output,
                promptfooUrl: opts.promptfooUrl,
                rootDir: ctx.config.rootDir,
            });
        }
        catch (err) {
            process.exitCode = 1;
            if (err instanceof Error)
                console.error(err.message);
        }
    });
    addOutputDirOption(cmd);
    return cmd;
}
