// tools/generate-skill.ts — Generate skills for AI agents
// Uses skill-generator engine: generateSkill()
import { t, ti } from '../i18n/index.js';
import { knowledgeStore, specStore } from '../storage/index.js';
import { generateSkill } from '../engine/skill-generator.js';
export async function handleGenerateSkill(args) {
    const { projectId, platform, skillType, name, description, specId } = args;
    const knowledge = await knowledgeStore.getKnowledge(projectId);
    if (!knowledge) {
        return {
            content: [
                {
                    type: 'text',
                    text: ti('errors.projectNotFound', { projectId }),
                },
            ],
            isError: true,
        };
    }
    // Optionally load spec content for context
    let specContent;
    if (specId) {
        const spec = await specStore.getSpec(projectId, specId);
        if (spec) {
            specContent = `Spec: ${spec.title}\nType: ${spec.type}\nScope: ${spec.scope}\nTarget: ${spec.target}\nTags: ${spec.tags.join(', ')}`;
        }
    }
    const result = await generateSkill(platform, skillType, name, description, knowledge, specContent);
    // Format output
    const lines = [
        `## ${t('tools.generate_skill.description')}`,
        '',
        `**Platform:** ${result.platform}`,
        `**Skill type:** ${skillType}`,
        `**Name:** ${name}`,
        '',
        `**Message:** ${result.message}`,
        '',
    ];
    // Output generated files
    for (const file of result.files) {
        lines.push(`### File: \`${file.path}\``);
        lines.push('');
        lines.push(`\`\`\`${file.format === 'markdown' ? 'markdown' : file.format}\``);
        lines.push(file.content);
        lines.push('```');
        lines.push('');
    }
    // Install instructions
    lines.push('### Installation');
    lines.push('');
    lines.push(result.installInstructions);
    return {
        content: [{ type: 'text', text: lines.join('\n') }],
    };
}
//# sourceMappingURL=generate-skill.js.map