/**
 * CLI boundary normalization for evaluation mode names.
 *
 * Legacy CLI users pass variant names like "baseline" or "agentic" as the
 * --mode flag. This module normalizes those to the canonical mode ("literacy")
 * plus a variant field, so downstream pipeline code only ever sees canonical
 * mode names.
 */
import { CANONICAL_EVAL_MODES, LEGACY_EVAL_MODE_ALIASES, } from "../_vendor/ailf-shared/index.js";
// ---------------------------------------------------------------------------
// Constants (derived from shared package — single source of truth)
// ---------------------------------------------------------------------------
/** The 5 canonical evaluation modes. */
const CANONICAL_MODES = new Set(CANONICAL_EVAL_MODES);
/**
 * Literacy variant name constants.
 *
 * Production code imports these instead of scattering legacy string literals.
 * Defined here (alongside the normalizer) so all variant name definitions
 * live in one file — the single source of truth for the legacy-to-canonical
 * mapping.
 */
export const LiteracyVariant = {
    /** Standard with-docs / without-docs evaluation (legacy mode name: "baseline") */
    STANDARD: "baseline",
    /** Agentic evaluation — model uses tools to find docs */
    AGENTIC: "agentic",
    /** Observed mode — HTTP-instrumented behavior observation */
    OBSERVED: "observed",
    /** Full mode — standard + agentic combined */
    FULL: "full",
};
/**
 * Legacy CLI names that are really literacy variants, not distinct modes.
 * Each maps to `mode: "literacy"` with the original name as the variant.
 */
const LEGACY_LITERACY_VARIANTS = new Set(LEGACY_EVAL_MODE_ALIASES);
/** Union of all accepted input strings for error messages. */
const ALL_ACCEPTED = [
    ...Array.from(CANONICAL_MODES),
    ...Array.from(LEGACY_LITERACY_VARIANTS),
];
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
/**
 * Normalize a raw CLI mode string to a canonical mode + optional variant.
 *
 * Legacy names ("baseline", "agentic", "observed", "full") are mapped to
 * `{ mode: "literacy", variant: "<name>" }` and emit a deprecation warning
 * on stderr. Canonical names pass through unchanged.
 *
 * @throws {Error} If the input is not a recognized mode or variant name.
 */
export function normalizeMode(input) {
    if (LEGACY_LITERACY_VARIANTS.has(input)) {
        console.warn(`⚠ Deprecated: --mode ${input} is a legacy alias. Use --mode literacy --variant ${input} instead.`);
        // The membership check above narrows `input` to LITERACY_VARIANTS — the
        // cast is to the closed type, not a widening.
        return { mode: "literacy", variant: input };
    }
    if (CANONICAL_MODES.has(input)) {
        return { mode: input };
    }
    throw new Error(`Unknown mode "${input}". Valid modes: ${ALL_ACCEPTED.join(", ")}`);
}
