|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * 测试潜在技能提示功能 |
| 4 | + */ |
| 5 | + |
| 6 | +import { getConfig } from './src/config.js'; |
| 7 | +import { getSystemPrompt } from './src/prompt-builder.js'; |
| 8 | +import { createSkillRegistry } from './src/skills/index.js'; |
| 9 | + |
| 10 | +async function testPotentialSkills() { |
| 11 | + console.log('========================================'); |
| 12 | + console.log('测试潜在技能提示功能'); |
| 13 | + console.log('========================================\n'); |
| 14 | + |
| 15 | + try { |
| 16 | + // 1. 加载配置 |
| 17 | + console.log('1️⃣ 加载配置...'); |
| 18 | + const config = await getConfig(); |
| 19 | + console.log(' ✅ 配置加载成功\n'); |
| 20 | + |
| 21 | + // 2. 创建技能注册表 |
| 22 | + console.log('2️⃣ 创建技能注册表...'); |
| 23 | + const registry = createSkillRegistry({ |
| 24 | + globalDir: `${process.env.HOME}/.closer-code/skills`, |
| 25 | + projectDir: '.closer-code/skills' |
| 26 | + }); |
| 27 | + await registry.initialize(); |
| 28 | + console.log(' ✅ 注册表初始化成功\n'); |
| 29 | + |
| 30 | + // 3. 获取潜在可用技能 |
| 31 | + console.log('3️⃣ 获取潜在可用技能...'); |
| 32 | + const potentialSkills = await registry.discover(); |
| 33 | + console.log(` 发现 ${potentialSkills.length} 个潜在技能:`); |
| 34 | + potentialSkills.forEach(s => { |
| 35 | + console.log(` - ${s.name}: ${s.description.substring(0, 60)}...`); |
| 36 | + }); |
| 37 | + console.log(); |
| 38 | + |
| 39 | + // 4. 构建系统提示(包含潜在技能) |
| 40 | + console.log('4️⃣ 构建系统提示...'); |
| 41 | + const systemPrompt = await getSystemPrompt(config, false, [], potentialSkills); |
| 42 | + console.log(' ✅ 系统提示构建成功\n'); |
| 43 | + |
| 44 | + // 5. 检查系统提示中的潜在技能部分 |
| 45 | + console.log('5️⃣ 验证系统提示内容...'); |
| 46 | + |
| 47 | + if (systemPrompt.includes('## 📚 Available Skills (Potential)')) { |
| 48 | + console.log(' ✅ 找到"潜在可用技能"部分'); |
| 49 | + } else { |
| 50 | + console.log(' ❌ 未找到"潜在可用技能"部分'); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + // 检查每个技能是否在系统提示中 |
| 55 | + let allSkillsFound = true; |
| 56 | + for (const skill of potentialSkills) { |
| 57 | + if (systemPrompt.includes(`**${skill.name}**`)) { |
| 58 | + console.log(` ✅ 找到技能: ${skill.name}`); |
| 59 | + } else { |
| 60 | + console.log(` ❌ 未找到技能: ${skill.name}`); |
| 61 | + allSkillsFound = false; |
| 62 | + } |
| 63 | + |
| 64 | + if (systemPrompt.includes(skill.description)) { |
| 65 | + console.log(` ✅ 找到描述: ${skill.name}`); |
| 66 | + } else { |
| 67 | + console.log(` ❌ 未找到描述: ${skill.name}`); |
| 68 | + allSkillsFound = false; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + if (!allSkillsFound) { |
| 73 | + console.log('\n ❌ 部分技能未在系统提示中找到'); |
| 74 | + return; |
| 75 | + } |
| 76 | + |
| 77 | + console.log(); |
| 78 | + console.log('6️⃣ 系统提示中的"潜在可用技能"部分:'); |
| 79 | + console.log('---'); |
| 80 | + |
| 81 | + // 提取并显示潜在技能部分 |
| 82 | + const potentialSkillsStart = systemPrompt.indexOf('## 📚 Available Skills (Potential)'); |
| 83 | + const potentialSkillsEnd = systemPrompt.indexOf('## 📍 Current Context', potentialSkillsStart); |
| 84 | + |
| 85 | + if (potentialSkillsStart !== -1 && potentialSkillsEnd !== -1) { |
| 86 | + const potentialSkillsSection = systemPrompt.substring(potentialSkillsStart, potentialSkillsEnd); |
| 87 | + console.log(potentialSkillsSection); |
| 88 | + } else { |
| 89 | + console.log(' ❌ 无法提取潜在技能部分'); |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + console.log('---\n'); |
| 94 | + |
| 95 | + console.log('========================================'); |
| 96 | + console.log('✅ 所有测试通过!'); |
| 97 | + console.log('========================================\n'); |
| 98 | + |
| 99 | + console.log('📊 总结:'); |
| 100 | + console.log(`- ✅ 发现 ${potentialSkills.length} 个潜在技能`); |
| 101 | + console.log('- ✅ 所有技能都包含在系统提示中'); |
| 102 | + console.log('- ✅ AI 现在可以在启动时知道有哪些技能可用'); |
| 103 | + console.log('- ✅ AI 可以根据用户需求直接调用 skillLoad'); |
| 104 | + |
| 105 | + } catch (error) { |
| 106 | + console.error('\n❌ 测试失败:', error.message); |
| 107 | + console.error(error.stack); |
| 108 | + process.exit(1); |
| 109 | + } |
| 110 | +} |
| 111 | + |
| 112 | +// 运行测试 |
| 113 | +testPotentialSkills(); |
0 commit comments