// engine/ecosystem-absorber/capability-detector.ts — Scores and filters capabilities by relevance
const CATEGORY_SCORE_MAP = {
    api: 0.8,
    sdk: 0.75,
    'tool-use': 0.9,
    agent: 0.85,
    skill: 0.7,
    pattern: 0.5,
};
const STACK_SIGNALS = {
    react: ['frontend', 'ui', 'component', 'design'],
    typescript: ['sdk', 'type', 'library'],
    python: ['ml', 'ai', 'data', 'notebook'],
    docker: ['container', 'deployment', 'devops'],
    mcp: ['tool-use', 'agent', 'protocol'],
};
/**
 * Score a capability against a known project stack.
 */
function scoreCapability(cap, stackHints) {
    let base = CATEGORY_SCORE_MAP[cap.category] ?? 0.5;
    const lowerName = cap.name.toLowerCase();
    const lowerDesc = cap.description.toLowerCase();
    for (const hint of stackHints) {
        const signals = STACK_SIGNALS[hint] ?? [];
        const matched = signals.some((s) => lowerName.includes(s) || lowerDesc.includes(s));
        if (matched) {
            base = Math.min(1, base + 0.15);
        }
    }
    return Math.round(base * 100) / 100;
}
/**
 * Generate an actionable suggestion for a capability.
 */
function buildSuggestion(cap, stackHints) {
    if (cap.suggestion) {
        return cap.suggestion;
    }
    const stackHint = stackHints.length > 0 ? ` (detected stack: ${stackHints.join(', ')})` : '';
    return `Consider integrating "${cap.name}" from ${cap.source}${stackHint}`;
}
/**
 * Score and rank ecosystem capabilities by relevance to project context.
 * Returns top N most relevant, each with updated relevance score and suggestion.
 */
export function rankCapabilities(capabilities, stackHints, topN = 10) {
    const scored = capabilities.map((cap) => ({
        ...cap,
        relevance: scoreCapability(cap, stackHints),
        suggestion: buildSuggestion(cap, stackHints),
        actionable: cap.relevance > 0.5 || cap.actionable,
    }));
    return scored.sort((a, b) => b.relevance - a.relevance).slice(0, topN);
}
/**
 * Extract actionable suggestions as plain text lines.
 */
export function extractSuggestions(capabilities) {
    return capabilities
        .filter((c) => c.actionable && typeof c.suggestion === 'string')
        .map((c) => c.suggestion)
        .slice(0, 5);
}
//# sourceMappingURL=capability-detector.js.map