// tools/suggest-stack.ts — Recommend technology stack
// Uses web-fetcher engine: suggestStack()
import { t } from '../i18n/index.js';
import { knowledgeStore, globalStore } from '../storage/index.js';
import { suggestStack } from '../engine/web-fetcher.js';
import { adjustRecommendationRanking } from '../engine/self-improver.js';
export async function handleSuggestStack(args) {
    const { projectType, requirements, constraints = [], projectId } = args;
    // If projectId provided, enrich with project knowledge
    let contextInfo = '';
    if (projectId) {
        const knowledge = await knowledgeStore.getKnowledge(projectId);
        if (knowledge) {
            contextInfo =
                `\n\n**Project context:** ${knowledge.language}` +
                    (knowledge.framework ? ` / ${knowledge.framework}` : '') +
                    ` — architecture: ${knowledge.architecture.primary}` +
                    ` — database: ${knowledge.database}`;
        }
    }
    // SPEC-012: Load developer preferences to adjust recommendation ranking
    const developerPrefs = await globalStore.getDeveloperPreferences();
    const result = await suggestStack(projectType, requirements, constraints);
    // Apply developer preference rankings to ecosystem items
    const ecosystemItems = [...result.primary.ecosystem, ...result.alternative.ecosystem];
    const rankings = adjustRecommendationRanking(ecosystemItems, developerPrefs);
    /* v8 ignore next 3 */
    const rejectedItems = [...rankings.entries()]
        .filter(([, score]) => score < -1)
        .map(([tool]) => tool);
    // Format primary recommendation
    const primaryLines = [
        `## ${t('tools.suggest_stack.description')}`,
        '',
        '### Primary Recommendation',
        '',
        `| Aspect | Value |`,
        `|--------|-------|`,
        `| **Language** | ${result.primary.language} |`,
        `| **Framework** | ${result.primary.framework} |`,
        `| **Version** | ${result.primary.version} |`,
        `| **Database** | ${result.primary.database} |`,
        result.primary.orm ? `| **ORM** | ${result.primary.orm} |` : '',
        result.primary.auth ? `| **Auth** | ${result.primary.auth} |` : '',
        `| **Deployment** | ${result.primary.deployment} |`,
        '',
        `**Reasoning:** ${result.primary.reasoning}`,
        '',
        `**Ecosystem:** ${result.primary.ecosystem.join(', ')}`,
    ].filter(Boolean);
    // Format alternative
    const altLines = [
        '',
        '### Alternative Recommendation',
        '',
        `| Aspect | Value |`,
        `|--------|-------|`,
        `| **Language** | ${result.alternative.language} |`,
        `| **Framework** | ${result.alternative.framework} |`,
        `| **Version** | ${result.alternative.version} |`,
        `| **Database** | ${result.alternative.database} |`,
        result.alternative.orm ? `| **ORM** | ${result.alternative.orm} |` : '',
        result.alternative.auth ? `| **Auth** | ${result.alternative.auth} |` : '',
        `| **Deployment** | ${result.alternative.deployment} |`,
        '',
        `**Reasoning:** ${result.alternative.reasoning}`,
        '',
        `**Ecosystem:** ${result.alternative.ecosystem.join(', ')}`,
    ].filter(Boolean);
    // Why not others
    const whyNotLines = [
        '',
        '### Why Not Others',
        '',
        ...result.whyNotOthers.map((w) => `- **${w.name}:** ${w.reason}`),
    ];
    // MCP compatibility
    const mcpLines = [
        '',
        '### MCP Compatibility',
        '',
        '| MCP | Compatible | Notes |',
        '|-----|-----------|-------|',
        ...result.mcpCompatibility.map((m) => `| ${m.mcp} | ${m.compatible ? 'Yes' : 'No'} | ${m.notes} |`),
    ];
    const prefsNote = rejectedItems.length > 0
        ? `\n\n> **Note:** Based on your preferences, these were previously rejected: ${rejectedItems.join(', ')}`
        : '';
    const text = [
        ...primaryLines,
        ...altLines,
        ...whyNotLines,
        ...mcpLines,
        contextInfo,
        prefsNote,
        '',
        `_Last checked: ${result.lastChecked}_`,
    ].join('\n');
    return {
        content: [{ type: 'text', text }],
    };
}
//# sourceMappingURL=suggest-stack.js.map