// engine/workflow-validator/model-selector.ts — SPEC-053
// Suggests appropriate AI model (haiku/sonnet/opus) based on task description keywords.
// === Keyword maps (loaded from catalog in practice; defined here for engine purity) ===
const HAIKU_KEYWORDS = [
    'search',
    'explore',
    'read',
    'grep',
    'summarize',
    'find files',
    'list',
    'check status',
    'read-only',
    'scan',
    'view',
    'inspect',
    'look',
    'locate',
    'browse',
];
const SONNET_KEYWORDS = [
    'implement',
    'write',
    'test',
    'refactor',
    'fix',
    'create',
    'update',
    'edit',
    'generate',
    'build',
    'code',
    'develop',
    'add feature',
    'patch',
    'migrate',
];
const OPUS_KEYWORDS = [
    'architecture',
    'design system',
    'complex debug',
    'multi-system',
    'plan phase',
    'strategy',
    'deep reasoning',
    'cross-system',
    'plan',
    'decide',
    'evaluate tradeoffs',
    'system design',
    'investigate',
];
// === Scoring ===
function countMatches(description, keywords) {
    const lower = description.toLowerCase();
    return keywords.filter((kw) => lower.includes(kw)).length;
}
// === Public API ===
export function suggestModel(taskDescription) {
    const haikuScore = countMatches(taskDescription, HAIKU_KEYWORDS);
    const sonnetScore = countMatches(taskDescription, SONNET_KEYWORDS);
    const opusScore = countMatches(taskDescription, OPUS_KEYWORDS);
    const maxScore = Math.max(haikuScore, sonnetScore, opusScore);
    let model;
    let reason;
    if (maxScore === 0) {
        // Default to sonnet — handles 80% of tasks
        model = 'sonnet';
        reason =
            'No strong keyword match found. Defaulting to sonnet — the right model for most implementation and write tasks.';
    }
    else if (opusScore === maxScore) {
        model = 'opus';
        reason =
            'Task involves architecture, strategy, or complex multi-system reasoning — use opus for deep thinking.';
    }
    else if (haikuScore === maxScore) {
        model = 'haiku';
        reason =
            'Task is read-only (search, explore, summarize) — use haiku for fast, cheap execution.';
    }
    else {
        model = 'sonnet';
        reason =
            'Task involves implementation, writing, or testing — use sonnet (default for 80% of tasks).';
    }
    const confidence = maxScore >= 2 ? 'high' : maxScore === 1 ? 'medium' : 'low';
    return { model, reason, confidence };
}
export function getModelRulesFromCatalog(catalog) {
    return catalog.modelSelectionRules;
}
/**
 * Like suggestModel but uses externally-loaded rules instead of hardcoded keywords.
 * Use this in tool handlers that load rules from workflow-conventions-catalog.json.
 */
export function suggestModelFromRules(taskDescription, rules) {
    const haikuScore = countMatches(taskDescription, rules.haiku);
    const sonnetScore = countMatches(taskDescription, rules.sonnet);
    const opusScore = countMatches(taskDescription, rules.opus);
    const maxScore = Math.max(haikuScore, sonnetScore, opusScore);
    let model;
    let reason;
    if (maxScore === 0) {
        model = 'sonnet';
        reason =
            'No strong keyword match found. Defaulting to sonnet — the right model for most implementation and write tasks.';
    }
    else if (opusScore === maxScore) {
        model = 'opus';
        reason =
            'Task involves architecture, strategy, or complex multi-system reasoning — use opus for deep thinking.';
    }
    else if (haikuScore === maxScore) {
        model = 'haiku';
        reason =
            'Task is read-only (search, explore, summarize) — use haiku for fast, cheap execution.';
    }
    else {
        model = 'sonnet';
        reason =
            'Task involves implementation, writing, or testing — use sonnet (default for 80% of tasks).';
    }
    const confidence = maxScore >= 2 ? 'high' : maxScore === 1 ? 'medium' : 'low';
    return { model, reason, confidence };
}
//# sourceMappingURL=model-selector.js.map