test-serializer.js 3.74 KB
/**
 * 验证脚本 — 用 codebase-explorer 测试 Genome 序列化器
 *
 * 用法: node server/src/engine/test-serializer.js
 */
const path = require('path');
const { serializeSkillToGenome, scanSkillsDirectory } = require('./serializer');

const SKILLS_DIR = path.join(require('os').homedir(), '.gemini/antigravity/skills');

console.log('═══════════════════════════════════════');
console.log('  Genome Serializer 验证');
console.log('═══════════════════════════════════════\n');

// ── 单文件分解 ──
const targetSkill = path.join(SKILLS_DIR, 'codebase-explorer/SKILL.md');
console.log(`📄 分解目标: ${targetSkill}\n`);

const genome = serializeSkillToGenome(targetSkill);

// 打印元信息
console.log('── Meta ──');
console.log(`  Name:     ${genome.meta.name}`);
console.log(`  Category: ${genome.meta.category}`);
console.log(`  Triggers: ${genome.meta.triggers.join(', ')}`);
console.log();

// 打印各维度统计
const dims = [
  { key: 'mentalModels', icon: '🧠', name: '心智模型' },
  { key: 'patternLibrary', icon: '📚', name: '模式库' },
  { key: 'judgment', icon: '⚖️', name: '判断力' },
  { key: 'toolFluency', icon: '🔧', name: '工具流利度' },
  { key: 'taste', icon: '✨', name: '品味' },
  { key: 'scarTissue', icon: '🩹', name: '伤疤记忆' },
];

for (const dim of dims) {
  const data = genome[dim.key];
  const counts = {};
  for (const [k, v] of Object.entries(data)) {
    counts[k] = Array.isArray(v) ? v.length : (typeof v === 'object' ? Object.keys(v).length : 1);
  }
  const total = Object.values(counts).reduce((a, b) => a + b, 0);
  console.log(`${dim.icon} ${dim.name} (${total} 条目)`);
  for (const [k, count] of Object.entries(counts)) {
    console.log(`  ├─ ${k}: ${count}`);
  }
  console.log();
}

// 打印具体内容(抽样)
console.log('── 抽样详情 ──\n');

if (genome.mentalModels.ironLaws.length) {
  console.log('🧠 铁律:');
  for (const law of genome.mentalModels.ironLaws) {
    console.log(`  • ${typeof law === 'string' ? law : JSON.stringify(law)}`);
  }
  console.log();
}

if (genome.scarTissue.antiPatterns.length) {
  console.log('🩹 反模式:');
  for (const ap of genome.scarTissue.antiPatterns.slice(0, 3)) {
    console.log(`  • ${ap.pattern} → ${ap.correction || ap.symptom}`);
  }
  console.log();
}

if (genome.judgment.decisionRules.length) {
  console.log('⚖️ 决策规则:');
  for (const rule of genome.judgment.decisionRules) {
    console.log(`  • ${rule}`);
  }
  console.log();
}

if (genome.toolFluency.coreTools.length) {
  console.log('🔧 核心工具:');
  console.log(`  ${genome.toolFluency.coreTools.map(t => t.name).join(', ')}`);
  console.log();
}

// ── 批量扫描 ──
console.log('═══════════════════════════════════════');
console.log('  批量扫描 Skills 目录');
console.log('═══════════════════════════════════════\n');

const allGenomes = scanSkillsDirectory(SKILLS_DIR);
console.log(`扫描到 ${allGenomes.length} 个 Skill:\n`);

for (const g of allGenomes) {
  const total = [
    g.mentalModels, g.patternLibrary, g.judgment,
    g.toolFluency, g.taste, g.scarTissue,
  ].reduce((sum, dim) => {
    return sum + Object.values(dim).reduce((s, v) =>
      s + (Array.isArray(v) ? v.length : (typeof v === 'object' ? Object.keys(v).length : 1)), 0);
  }, 0);

  console.log(`  📦 ${g.meta.name.padEnd(25)} ${total} 条目  [${g.meta.category}]`);
}

console.log('\n✅ Genome Serializer 验证完成');