/**
 * Filter knowledge items by relevance to the project context.
 * Returns items sorted by relevance score (highest first).
 */
export function filterByContext(items, context) {
    const scored = items.map((item) => ({
        item,
        score: calculateRelevance(item, context),
    }));
    return scored
        .filter((s) => s.score > 0.1) // minimum relevance threshold
        .sort((a, b) => b.score - a.score)
        .map((s) => s.item);
}
/**
 * Calculate relevance score (0-1) for an item given the project context.
 */
function calculateRelevance(item, context) {
    let score = 0.3; // base score
    // Target match (0.25 weight)
    if (item.applicableTargets.includes(context.target) ||
        item.applicableTargets.includes('fullstack')) {
        score += 0.25;
    }
    // Stack match (0.25 weight)
    const stackLower = context.stack.map((s) => s.toLowerCase());
    const itemText = `${item.title} ${item.description} ${item.tags.join(' ')}`.toLowerCase();
    const stackMatches = stackLower.filter((s) => itemText.includes(s)).length;
    if (stackMatches > 0) {
        score += Math.min(0.25, stackMatches * 0.1);
    }
    // Severity bonus (0.1 weight)
    if (item.severity === 'required') {
        score += 0.1;
    }
    else if (item.severity === 'recommended') {
        score += 0.05;
    }
    // App type match (0.1 weight)
    if (context.appType && itemText.includes(context.appType.toLowerCase())) {
        score += 0.1;
    }
    return Math.min(1, score);
}
//# sourceMappingURL=stack-filter.js.map