/**
 * Literacy mode base — shared evaluation methodology for documentation literacy.
 *
 * Defines HOW literacy evaluations are scored (rubrics, weights, prompts),
 * independently of WHAT documentation is being evaluated. Domain presets
 * like `sanity-literacy` target this mode base and add their own sources,
 * features, and doc fetcher.
 *
 * @see docs/modes.md
 */
import { modelMatchesMode, resolveModelVariants, } from "../../../_vendor/ailf-core/index.js";
import { LITERACY_PROMPT_TEMPLATES } from "../mode-handlers/literacy/index.js";
// ---------------------------------------------------------------------------
// Mode base factory
// ---------------------------------------------------------------------------
export function createLiteracyModeBase() {
    return {
        mode: {
            id: "literacy",
            label: "Documentation Literacy",
            validProviderPatterns: ["^openai:", "^anthropic:", "^file://"],
            rubricTemplateIds: [
                "task-completion",
                "code-correctness",
                "doc-coverage",
            ],
            handlerModule: "./mode-handlers/literacy/index.js",
            variants: [
                {
                    id: "baseline",
                    label: "Standard (baseline)",
                    description: "Standard with-docs and without-docs evaluation prompts",
                },
                {
                    id: "observed",
                    label: "Observed (HTTP-instrumented)",
                    description: "HTTP-instrumented evaluation that records model behavior",
                },
                {
                    id: "agentic-naive",
                    label: "Agentic (naive)",
                    description: "Model uses tools to find docs with default system prompt",
                },
                {
                    id: "agentic-optimized",
                    label: "Agentic (optimized)",
                    description: "Model uses tools to find docs with optimized system prompt",
                },
            ],
        },
        rubricTemplates: [
            {
                id: "task-completion",
                dimension: "task-completion",
                header: "Score task completion from 0 to 100:",
                scale: [
                    "0: Couldn't attempt — missing critical information",
                    "20: Attempted but fundamentally wrong approach",
                    "50: Partial implementation — major functional gaps",
                    "80: Mostly complete — minor issues or missing edge cases",
                    "100: Fully functional code — works as expected",
                ],
                criteriaLabel: "Must demonstrate:",
            },
            {
                id: "code-correctness",
                dimension: "code-correctness",
                header: "Score code correctness from 0 to 100:",
                scale: [
                    "0: Broken code, syntax errors, or deprecated APIs",
                    "30: Works but uses anti-patterns or inefficient approaches",
                    "50: Works but not idiomatic",
                    "80: Follows most best practices",
                    "100: Follows all best practices, idiomatic implementation",
                ],
                criteriaLabel: "Check for:",
            },
            {
                id: "doc-coverage",
                dimension: "doc-coverage",
                header: "Score documentation coverage from 0 to 100:",
                scale: [
                    "0: Had to hallucinate/guess most implementation details",
                    "30: Significant gaps — filled with assumptions",
                    "50: Some gaps — inferred from partial information",
                    "80: Minor gaps — almost everything was documented",
                    "100: Complete coverage — all necessary info was in docs",
                ],
            },
        ],
        scoringProfiles: {
            default: {
                "task-completion": 0.5,
                "code-correctness": 0.25,
                "doc-coverage": 0.25,
            },
            "output-only": {
                "task-completion": 0.6,
                "code-correctness": 0.4,
            },
        },
        promptTemplates: LITERACY_PROMPT_TEMPLATES,
    };
}
// ---------------------------------------------------------------------------
// Shared variant matching helper
// ---------------------------------------------------------------------------
/** Lazily initialized mode base — avoids re-creating on every call */
let _cachedBase;
function getLiteracyModeBase() {
    if (!_cachedBase)
        _cachedBase = createLiteracyModeBase();
    return _cachedBase;
}
/**
 * Check whether a model participates in a specific literacy variant.
 *
 * A model matches if:
 * 1. It's enrolled in the `literacy` eval mode (or has no `modes` field)
 * 2. The variant is in its resolved variant set (defaults to all variants)
 *
 * This is the single source of truth for literacy variant matching —
 * import this instead of reimplementing the pattern.
 */
export function modelMatchesLiteracyVariant(model, variant) {
    if (!modelMatchesMode(model, "literacy"))
        return false;
    const variants = resolveModelVariants(model, getLiteracyModeBase());
    if (!variants)
        return true;
    return variants.includes(variant);
}
