/**
 * run command — the main evaluation entry point.
 *
 * Renamed from `ailf pipeline` to `ailf run` per W0077 Phase 1
 * (see docs/design-docs/pipeline-command-surface.md §3). The command drives
 * the evaluation pipeline; the orchestrator internals retain the "pipeline"
 * name because they describe a multi-step process, not the CLI verb.
 *
 * Defines all 44+ CLI flags via Commander, resolves them into a typed
 * options object, bridges to process.env for downstream modules, and
 * delegates to runPipeline().
 *
 * @see docs/guides/cli-guide.md for per-flag behavior notes, or
 * docs/references/cli-reference.md for the auto-generated flag matrix.
 */
import { Command } from "commander";
import { addAgenticOptions, addDebugOptions, addSanityScopeOptions, } from "./shared/options.js";
export function createRunCommand() {
    const cmd = new Command("run")
        .description("Run the full evaluation pipeline")
        .option("-m, --mode <mode>", "Evaluation mode: literacy (default), mcp-server, agent-harness, knowledge-probe, custom. Legacy aliases (baseline, agentic, observed, full) are accepted and normalized to literacy + variant.", "literacy")
        .option("--variant <variant>", "Literacy variant: full (default — standard + agentic), baseline (standard only), agentic (agentic only), observed. Only applies to --mode literacy.")
        .option("-s, --source <name>", "Documentation source name (from sources.yaml)")
        .option("-n, --dry-run", "Validate configuration only, no execution", false)
        .option("--no-fetch", "Reuse cached documentation contexts")
        .option("--no-eval", "Recalculate from existing eval results")
        .option("--no-cache", "Bypass all pipeline-level caching")
        .option("--no-remote-cache", "Disable Content Lake cache lookup (local cache still active)")
        .option("--no-auto-scope", "Disable release-aware auto-scoping (evaluate all tasks even when a perspective is set)")
        .option("-a, --area <areas>", "Scope to feature areas (comma-separated)")
        .option("-t, --task <id>", "Scope to specific task ID")
        .option("--tag <tags>", "Scope to tasks with matching tags (comma-separated, repeatable)", (val, prev) => [
        ...prev,
        ...val
            .split(",")
            .map((s) => s.trim())
            .filter(Boolean),
    ], [])
        .option("--changed-docs <slugs>", "Auto-scope to tasks affected by these document slugs")
        .option("--before-source <name>", "Swap the doc source to a `before` state and run a paired evaluation for impact analysis. Pairs with `ailf baseline` and `--compare`. Distinct from `--compare <baseline>`, which compares scores against a saved snapshot.")
        .option("-c, --compare [baseline]", "Compare scores against the latest baseline. Pass a path to pin a specific baseline file (e.g. --compare results/baselines/2026-04-22.json).")
        .option("--threshold <n>", "Noise threshold for comparison (default: 2)", parseFloat)
        .option("-p, --publish", "Write report to Sanity + fan out to sinks (auto-enabled for full runs when report store is configured)")
        .option("--no-publish", "Suppress auto-publishing")
        .option("--publish-tag <tag>", "Label for published report")
        .option("--summary", "Force post-run diagnosis summary (overrides config and env var)")
        .option("--no-summary", "Suppress post-run diagnosis summary (default is on)")
        .option("--config <path>", "Load pipeline config from a TS/JS/YAML/JSON file (overrides most CLI flags)")
        .option("-o, --output <path>", "Write PR comment markdown to file")
        .option("--promptfoo-url <url>", "Promptfoo share URL for report")
        .option("--remote", "Submit evaluation to the AILF API instead of running locally", false)
        .option("--api-key <value>", "API key for --remote dispatch. Wins over AILF_API_KEY and any value loaded from the project .env file (W0202).")
        .option("--no-artifacts-write", "Run artifact writers in dry-run mode — log intended writes, touch no storage")
        // D0037 caller envelope (W0069) — threads through --remote so the
        // server-side pipeline attributes provenance to the caller, not the
        // API gateway runner. All env-var equivalents are honored too;
        // explicit flags win over env vars.
        .option("--classification <value>", "Run classification for provenance: official | adhoc | experimental | test | external. Overrides AILF_CLASSIFICATION. See D0037.")
        .option("--purpose <text>", 'Free-text "why I ran this" attached to provenance. Overrides AILF_PURPOSE.')
        .option("--label <value>", "Free-form searchable label (repeatable). Appends to any AILF_LABELS env value.", (val, prev) => [
        ...prev,
        ...val
            .split(",")
            .map((s) => s.trim())
            .filter(Boolean),
    ], [])
        .action(async (opts) => {
        const { executePipeline } = await import("./pipeline-action.js");
        await executePipeline(opts);
    });
    // Add shared option groups
    addDebugOptions(cmd);
    addSanityScopeOptions(cmd);
    addAgenticOptions(cmd);
    return cmd;
}
