import { z } from 'zod';
import { t } from '../../i18n/index.js';
import { safeTracked, safeLicensed } from '../safe-handler.js';
import { ChecklistFocusEnum, AuditCategoryEnum } from '../schemas/index.js';
import { handleDetectDrift } from '../detect-drift.js';
import { handleSummarizeSpec } from '../summarize-spec.js';
import { handleGenerateChecklist } from '../generate-checklist.js';
import { handleReconcileSpec } from '../reconcile-spec.js';
import { handleLearn } from '../learn.js';
import { handleAudit } from '../audit.js';
import { handleConsultDocs } from '../consult-docs.js';
import { handleDiscoverMcps } from '../discover-mcps.js';
import { handleSuggestMcps } from '../suggest-mcps.js';
import { handleAnalyzeSpecDependencies } from '../analyze-spec-dependencies.js';
/**
 * Registers drift detection, analysis, and discovery tools (tools 11–19) on the MCP server.
 */
export function registerAnalysisTools(server) {
    // 11. detect_drift
    server.registerTool('detect_drift', {
        description: t('tools.detect_drift.description'),
        inputSchema: {
            specId: z.string().max(500).describe('Spec ID to check'),
            projectId: z.string().max(500).describe('Project ID'),
            mode: z
                .enum(['full', 'quick'])
                .optional()
                .describe('Analysis mode: full | quick (default: quick)'),
            outputFormat: z
                .enum(['report', 'ci-json', 'github-annotations'])
                .optional()
                .describe('Output format: report | ci-json | github-annotations'),
            threshold: z.number().optional().describe('Drift tolerance threshold 0-100 (default: 10)'),
        },
    }, safeTracked('detect_drift', async (args) => handleDetectDrift(args)));
    // 12. summarize_spec
    server.registerTool('summarize_spec', {
        description: t('tools.summarize_spec.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            specId: z.string().max(500).describe('Spec ID to summarize'),
            projectId: z.string().max(500).describe('Project ID'),
            format: z
                .enum(['executive', 'technical', 'oneliner'])
                .optional()
                .describe('Summary format: executive | technical | oneliner (default: technical)'),
        },
    }, safeTracked('summarize_spec', async (args) => handleSummarizeSpec(args)));
    // 13. generate_checklist
    server.registerTool('generate_checklist', {
        description: t('tools.generate_checklist.description'),
        inputSchema: {
            specId: z.string().max(500).describe('Spec ID'),
            projectId: z.string().max(500).describe('Project ID'),
            focus: z
                .array(ChecklistFocusEnum)
                .max(100)
                .optional()
                .describe('Focus areas for the checklist'),
        },
    }, safeLicensed('generate_checklist', async (args) => handleGenerateChecklist(args)));
    // 14. reconcile_spec
    server.registerTool('reconcile_spec', {
        description: t('tools.reconcile_spec.description'),
        inputSchema: {
            specId: z.string().max(500).describe('Spec ID to reconcile'),
            projectId: z.string().max(500).describe('Project ID'),
            autoDetect: z
                .boolean()
                .optional()
                .describe('Auto-detect changes from implementation (default: true)'),
            livingSpec: z
                .boolean()
                .optional()
                .describe('Enable living spec mode: compare acceptance criteria against codebase, auto-mark criteria as met/pending/drift, update progress.md (default: false)'),
            changes: z
                .array(z.object({
                section: z.string().max(500),
                originalValue: z.string().max(10_000),
                newValue: z.string().max(10_000),
                reason: z.string().max(10_000),
                approved: z.boolean(),
            }))
                .max(1000)
                .optional()
                .describe('Manual changes to apply'),
        },
    }, safeLicensed('reconcile_spec', async (args) => handleReconcileSpec(args)));
    // 15. learn_pattern
    server.registerTool('learn_pattern', {
        description: t('tools.learn_pattern.description'),
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            type: z
                .enum(['architecture', 'convention', 'estimation', 'stack', 'quality'])
                .describe('Pattern type: architecture | convention | estimation | stack | quality'),
            pattern: z.string().max(10_000).describe('Pattern description'),
            source: z.string().max(500).optional().describe('Where this pattern was observed'),
        },
    }, safeTracked('learn_pattern', async (args) => handleLearn(args)));
    // 16. audit
    server.registerTool('audit', {
        description: t('tools.audit.description'),
        inputSchema: {
            path: z.string().max(4096).describe('Path to file or directory to audit'),
            projectId: z.string().max(500).describe('Project ID'),
            categories: z
                .array(AuditCategoryEnum)
                .max(100)
                .optional()
                .describe('Audit categories to check'),
            specId: z.string().max(500).optional().describe('Spec ID to audit against'),
        },
    }, safeLicensed('audit', async (args) => handleAudit(args)));
    // 17. consult_docs
    server.registerTool('consult_docs', {
        description: t('tools.consult_docs.description'),
        inputSchema: {
            topic: z.string().max(500).describe('Topic to search for'),
            projectId: z.string().max(500).describe('Project ID'),
            framework: z
                .string()
                .max(500)
                .optional()
                .describe('Framework to consult docs for (auto-detected if omitted)'),
        },
    }, safeTracked('consult_docs', async (args) => handleConsultDocs(args)));
    // 18. discover_mcps
    server.registerTool('discover_mcps', {
        description: t('tools.discover_mcps.description'),
        inputSchema: {
            configPath: z
                .string()
                .max(4096)
                .optional()
                .describe('Path to MCP config file (auto-detected if omitted)'),
            projectId: z.string().max(500).optional().describe('Project ID'),
        },
    }, safeLicensed('discover_mcps', async (args) => handleDiscoverMcps(args)));
    // 19. suggest_mcps
    server.registerTool('suggest_mcps', {
        description: t('tools.suggest_mcps.description'),
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            specId: z.string().max(500).optional().describe('Spec ID for context-specific suggestions'),
        },
    }, safeLicensed('suggest_mcps', async (args) => handleSuggestMcps(args)));
    // 20. analyze_spec_dependencies
    server.registerTool('analyze_spec_dependencies', {
        description: 'Analyze spec dependency graph: find critical path, detect circular dependencies, compute execution waves, and generate a Mermaid diagram of the dependency graph.',
        annotations: { readOnlyHint: true },
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            specIds: z
                .array(z.string().max(500))
                .max(1000)
                .optional()
                .describe('Optional list of spec IDs to analyze (default: all specs)'),
        },
    }, safeTracked('analyze_spec_dependencies', async (args) => handleAnalyzeSpecDependencies(args)));
}
//# sourceMappingURL=analysis-tools.js.map