/**
 * Skill 管理器示例
 * 展示如何加载和使用 Skill
 */

const { Framework } = require('../src');
const { SkillManagerPlugin } = require('../src/capabilities/skill-manager');

async function main() {
  console.log('=== Skill Manager Example ===\n');

  // 创建框架
  const framework = new Framework({ debug: true });

  // 创建 skills 目录（如果没有）
  const fs = require('fs');
  const skillsDir = './skills';
  if (!fs.existsSync(skillsDir)) {
    fs.mkdirSync(skillsDir, { recursive: true });
  }

  // 加载 Skill 管理器插件
  const skillPlugin = new SkillManagerPlugin({
    skillsDir: skillsDir,
  });

  await framework.loadPlugin(skillPlugin);

  // 列出所有加载的 skills
  console.log('\n--- Loaded Skills ---');
  const skills = skillPlugin.getAllSkills();
  console.log(`Found ${skills.length} skills:`);
  for (const skill of skills) {
    console.log(`  - ${skill.name}: ${skill.metadata.description}`);
  }

  // 获取单个 skill
  if (skillPlugin.hasSkill('hello-skill')) {
    console.log('\n--- Hello Skill ---');
    const helloSkill = skillPlugin.getSkill('hello-skill');
    console.log('Content preview:', helloSkill.content.substring(0, 100) + '...');
  }

  // 清理
  await framework.destroy();
  console.log('\n[Done]');
}

main().catch(console.error);
