test-serializer.js
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* 验证脚本 — 用 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 验证完成');