// engine/model-router/subtask-model-assigner.ts — SPEC-621: Auto model routing per subtask
// Assigns haiku/sonnet/opus to each subtask based on keyword signals, difficulty, and scope.
// ---------------------------------------------------------------------------
// Keyword lists
// ---------------------------------------------------------------------------
/** Keywords that indicate a read-only / search subtask → haiku. */
const HAIKU_KEYWORDS = [
    'search',
    'list',
    'find',
    'read',
    'scan',
    'grep',
    'explore',
    'check',
    'query',
    'display',
    'show',
    'report',
    'summary',
    'status',
    'audit',
    'inspect',
];
/** Keywords that indicate an architecture / multi-system subtask → opus. */
const OPUS_KEYWORDS = [
    'architecture',
    'architect',
    'design',
    'multi-system',
    'multisystem',
    'cross-module',
    'cross module',
    'multi_system',
    'rfc',
    'strategy',
    'distributed',
    'system design',
    'redesign',
    'migration',
    'plan the',
];
// ---------------------------------------------------------------------------
// Helper: keyword matching
// ---------------------------------------------------------------------------
function containsAnyKeyword(text, keywords) {
    const lower = text.toLowerCase();
    return keywords.some((kw) => lower.includes(kw));
}
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
/**
 * Assign a recommended model tier to a subtask based on its complexity signals.
 *
 * Rules (in priority order):
 * 1. Scope === "cross-module" → opus (regardless of other signals)
 * 2. Difficulty >= 4 → opus (regardless of other signals)
 * 3. Title contains opus keywords (architecture, design, etc.) → opus
 * 4. Title contains haiku keywords (search, list, find, etc.) → haiku
 * 5. Default for write/implement/refactor → sonnet
 */
export function assignModelToSubtask(subtask) {
    const { title, difficulty, scope } = subtask;
    // Cross-module scope or high difficulty always warrant opus
    if (scope === 'cross-module') {
        return 'opus';
    }
    if (difficulty !== undefined && difficulty >= 4) {
        return 'opus';
    }
    // Keyword-based classification
    if (containsAnyKeyword(title, OPUS_KEYWORDS)) {
        return 'opus';
    }
    if (containsAnyKeyword(title, HAIKU_KEYWORDS)) {
        return 'haiku';
    }
    // Default: write/implement/refactor tasks
    return 'sonnet';
}
// ---------------------------------------------------------------------------
// Cost estimation helpers
// ---------------------------------------------------------------------------
/** Approximate token cost (USD) per model tier for a typical subtask. */
const COST_PER_TIER = {
    haiku: 0.0003,
    sonnet: 0.003,
    opus: 0.015,
};
/**
 * Format an estimated cost string for a given model tier.
 * Returns a string like "$0.003".
 */
export function formatSubtaskCost(tier) {
    const cost = COST_PER_TIER[tier];
    return `$${cost.toFixed(4)}`;
}
/**
 * Build a model header line suitable for inclusion in agent prompts.
 * Format: "## Model: sonnet (--model claude-sonnet-4-6)"
 */
export function buildModelHeader(tier) {
    const modelIds = {
        haiku: 'claude-haiku-3-5',
        sonnet: 'claude-sonnet-4-6',
        opus: 'claude-opus-4-5',
    };
    return `## Model: ${tier} (--model ${modelIds[tier]})`;
}
//# sourceMappingURL=subtask-model-assigner.js.map