// tools/generate-adr.ts — Architecture Decision Records
// Analyzes a spec and project knowledge to generate structured ADRs
// documenting architectural decisions, options, tradeoffs, and rationale.
import { specStore, knowledgeStore, patternStore } from '../storage/index.js';
import { t, ti } from '../i18n/index.js';
import { generateDecisions, readSpecContent, buildEcosystemAnalysis, buildRecommendation, } from './generate-adr/index.js';
import { compactJson } from './output-formatter.js';
export async function handleGenerateADR(args) {
    const { specId, projectId, decisions: requestedDecisions } = args;
    const spec = await specStore.getSpec(projectId, specId);
    if (!spec) {
        return {
            content: [{ type: 'text', text: ti('spec.notFound', { id: specId }) }],
            isError: true,
        };
    }
    const knowledge = await knowledgeStore.getKnowledge(projectId);
    if (!knowledge) {
        return {
            content: [{ type: 'text', text: t('project.notFound') }],
            isError: true,
        };
    }
    const patterns = await patternStore.findPatternsByType(projectId, 'architecture');
    const specContent = await readSpecContent(spec);
    const decisions = generateDecisions(spec, knowledge, patterns, specContent, requestedDecisions);
    const ecosystemAnalysis = buildEcosystemAnalysis(knowledge);
    const recommendation = buildRecommendation(decisions, knowledge);
    const result = {
        decisions,
        ecosystemAnalysis,
        recommendation,
    };
    return {
        content: [
            {
                type: 'text',
                text: ti('tools.generate_adr.success', { count: String(decisions.length) }),
            },
            { type: 'text', text: compactJson(result, 500) },
        ],
    };
}
//# sourceMappingURL=generate-adr.js.map