import { z } from 'zod';
import { t } from '../../i18n/index.js';
import { safeTracked, safeLicensed } from '../safe-handler.js';
import { AgentPlatformEnum, SubAgentFrameworkEnum, ChallengeSpecFocusEnum, SpecIdSchema, } from '../schemas/index.js';
import { handleGenerateADR } from '../generate-adr.js';
import { handleDesignSchema } from '../design-schema.js';
import { handleDefineUIContract } from '../define-ui-contract.js';
import { handleChallengeSpec } from '../challenge-spec.js';
import { handleGenerateExecutionPlan } from '../generate-execution-plan.js';
import { handleSuggestStack } from '../suggest-stack.js';
import { handleCheckVersions } from '../check-versions.js';
import { handleGenerateSkill } from '../generate-skill.js';
import { handleDetectAgent } from '../detect-agent.js';
import { handleGenerateSubAgent } from '../generate-sub-agent.js';
import { handleGenerateRules } from '../generate-rules.js';
import { handleGenerateOrchestrationScript } from '../generate-orchestration-script.js';
import { handleRedTeam } from '../red-team.js';
import { resolveProjectId } from '../resolve-project-id.js';
/**
 * Registers design, challenge, stack, and agent tools (tools 20–30) on the MCP server.
 */
export function registerDesignStackTools(server) {
    // 20. generate_adr
    server.registerTool('generate_adr', {
        description: t('tools.generate_adr.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            specId: SpecIdSchema.describe('Spec ID'),
            projectId: z.string().max(500).describe('Project ID'),
            decisions: z
                .array(z.string().max(10_000))
                .max(100)
                .optional()
                .describe('Specific decisions to document'),
        },
    }, safeLicensed('generate_adr', async (args) => handleGenerateADR(args)));
    // 21. design_schema
    server.registerTool('design_schema', {
        description: t('tools.design_schema.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            specId: SpecIdSchema.describe('Spec ID'),
            projectId: z.string().max(500).describe('Project ID'),
            description: z
                .string()
                .max(10_000)
                .optional()
                .describe('Additional schema context or requirements'),
        },
    }, safeLicensed('design_schema', async (args) => handleDesignSchema(args)));
    // 22. define_ui_contract
    server.registerTool('define_ui_contract', {
        description: t('tools.define_ui_contract.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            specId: SpecIdSchema.describe('Spec ID'),
            projectId: z.string().max(500).describe('Project ID'),
            screens: z
                .array(z.string().max(500))
                .max(100)
                .optional()
                .describe('Specific screens to define contracts for'),
        },
    }, safeLicensed('define_ui_contract', async (args) => handleDefineUIContract(args)));
    // 23. challenge_spec
    server.registerTool('challenge_spec', {
        description: t('tools.challenge_spec.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            specId: SpecIdSchema.describe('Spec ID to challenge'),
            projectId: z
                .string()
                .max(500)
                .optional()
                .describe('Project ID hash. Prefer projectPath — stays correct after context compaction.'),
            projectPath: z
                .string()
                .max(4096)
                .optional()
                .describe('Absolute path to project root. Derives projectId automatically — always correct even after context compaction.'),
            focus: z
                .array(ChallengeSpecFocusEnum)
                .max(100)
                .optional()
                .describe('Focus areas for the challenge'),
        },
    }, safeLicensed('challenge_spec', async (args) => handleChallengeSpec(args)));
    // 24. generate_execution_plan
    server.registerTool('generate_execution_plan', {
        description: t('tools.generate_execution_plan.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            specId: SpecIdSchema.describe('Spec ID'),
            projectId: z.string().max(500).describe('Project ID'),
        },
    }, safeTracked('generate_execution_plan', async (args) => handleGenerateExecutionPlan(args)));
    // 25. suggest_stack
    server.registerTool('suggest_stack', {
        description: t('tools.suggest_stack.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            projectType: z
                .enum(['web', 'mobile', 'backend', 'fullstack', 'cli', 'library'])
                .describe('Project type: web | mobile | backend | fullstack | cli | library'),
            requirements: z.array(z.string().max(10_000)).max(1000).describe('Project requirements'),
            constraints: z
                .array(z.string().max(10_000))
                .max(100)
                .optional()
                .describe('Constraints (budget, team size, timeline, etc.)'),
            projectId: z.string().max(500).optional().describe('Project ID hash. Prefer projectPath.'),
            projectPath: z
                .string()
                .max(4096)
                .optional()
                .describe('Absolute path to project root. Derives projectId automatically.'),
        },
    }, safeTracked('suggest_stack', async (args) => {
        const typedArgs = args;
        const pid = resolveProjectId(typedArgs);
        const enrichedArgs = pid ? { ...args, projectId: pid } : args;
        return handleSuggestStack(enrichedArgs);
    }));
    // 26. check_versions
    server.registerTool('check_versions', {
        description: t('tools.check_versions.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            includeDevDeps: z
                .boolean()
                .optional()
                .describe('Include dev dependencies (default: false)'),
        },
    }, safeTracked('check_versions', async (args) => handleCheckVersions(args)));
    // 27. generate_skill
    server.registerTool('generate_skill', {
        description: t('tools.generate_skill.description'),
        annotations: { readOnlyHint: false },
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            platform: AgentPlatformEnum.describe('Target agent platform'),
            skillType: z
                .enum(['project-rules', 'domain-skill', 'workflow', 'convention'])
                .describe('Skill type: project-rules | domain-skill | workflow | convention'),
            name: z.string().max(500).describe('Skill name'),
            description: z.string().max(10_000).describe('Skill description'),
            specId: SpecIdSchema.optional().describe('Spec ID for context'),
        },
    }, safeLicensed('generate_skill', async (args) => handleGenerateSkill(args)));
    // 28. detect_agent
    server.registerTool('detect_agent', {
        description: t('tools.detect_agent.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
        },
    }, safeLicensed('detect_agent', async (args) => handleDetectAgent(args)));
    // 29. generate_sub_agent
    server.registerTool('generate_sub_agent', {
        description: t('tools.generate_sub_agent.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            framework: SubAgentFrameworkEnum.describe('Sub-agent framework'),
            agentName: z.string().max(500).describe('Name for the sub-agent'),
            role: z.string().max(10_000).describe('Role description for the sub-agent'),
            capabilities: z.array(z.string().max(500)).max(100).describe('List of capabilities'),
            tools: z
                .array(z.string().max(500))
                .max(100)
                .optional()
                .describe('Tools the sub-agent can use'),
            systemPrompt: z.string().max(1_000_000).optional().describe('Custom system prompt'),
            autoMemory: z
                .boolean()
                .optional()
                .describe('When true, adds autoMemory: true to the agent frontmatter and includes memory path info in the response'),
        },
    }, safeLicensed('generate_sub_agent', async (args) => handleGenerateSubAgent(args)));
    // 30. generate_rules
    server.registerTool('generate_rules', {
        description: t('tools.generate_rules.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            projectId: z.string().max(500).describe('Project ID'),
            platform: AgentPlatformEnum.describe('Target agent platform'),
            includeArchitecture: z
                .boolean()
                .optional()
                .describe('Include architecture rules (default: true)'),
            includeConventions: z
                .boolean()
                .optional()
                .describe('Include convention rules (default: true)'),
            includeQuality: z.boolean().optional().describe('Include quality rules (default: true)'),
            includeWorkflow: z.boolean().optional().describe('Include workflow rules (default: true)'),
            customRules: z
                .array(z.string().max(10_000))
                .max(100)
                .optional()
                .describe('Additional custom rules'),
        },
    }, safeLicensed('generate_rules', async (args) => handleGenerateRules(args)));
    // 31. generate_orchestration_script
    server.registerTool('generate_orchestration_script', {
        description: t('tools.generate_orchestration_script.description'),
        annotations: { readOnlyHint: true },
        inputSchema: {
            specIds: z
                .array(SpecIdSchema)
                .min(1)
                .max(100)
                .describe('List of canonical spec IDs to run in parallel (e.g. ["SPEC-013", "SPEC-014"])'),
            projectPath: z.string().max(4096).describe('Absolute path to the project root'),
            mainBranch: z.string().max(500).optional().describe('Main branch name (default: main)'),
            baseBranch: z
                .string()
                .max(500)
                .optional()
                .describe('Base branch for worktrees (default: develop)'),
        },
    }, safeLicensed('generate_orchestration_script', (args) => Promise.resolve(handleGenerateOrchestrationScript(args))));
    // 32. red_team
    server.registerTool('red_team', {
        description: 'Adversarial review — argues against the spec from first principles before approval. Runs pre-mortem, surfaces hidden assumptions, proposes alternatives.',
        annotations: { readOnlyHint: true },
        inputSchema: {
            specId: SpecIdSchema.describe('Spec ID to red-team'),
            projectId: z.string().max(500).describe('Project ID'),
            intensity: z
                .enum(['light', 'full'])
                .optional()
                .describe('light: top objections only (default). full: exhaustive analysis across all 6 lenses'),
        },
    }, safeLicensed('red_team', async (args) => handleRedTeam(args)));
}
//# sourceMappingURL=design-stack-tools.js.map