#!/usr/bin/env node // Fix W1: SKILL-REGISTRY markdown closing ** // Fix W2: hooksRegistered 27→29 // Fix W3: note about archived skills (cosmetic, stats source-of-truth is compile script) // Fix W4: agentsOpus 7→6, agentsSonnet 10→11 // Fix W5: fail-mode.js comment exit(1)→exit(2) const fs = require('fs'); const path = require('path'); const ROOT = path.resolve(__dirname, '../..'); // W1: Fix SKILL-REGISTRY.md line 8 missing closing ** const regPath = path.join(ROOT, 'SKILL-REGISTRY.md'); let reg = fs.readFileSync(regPath, 'utf8'); const oldLine = '- **最后更新: 2026-04-27 (v6.6.1)'; const newLine = '- **最后更新**: 2026-04-27 (v6.6.1)'; if (reg.includes(oldLine)) { fs.copyFileSync(regPath, regPath + '.bak'); reg = reg.replace(oldLine, newLine); fs.writeFileSync(regPath, reg, 'utf8'); console.log('W1 FIXED: SKILL-REGISTRY.md closing ** added'); } else { console.log('W1 SKIP: pattern not found or already fixed'); } // W2+W4: Fix stats-compiled.json counts const statsPath = path.join(ROOT, 'stats-compiled.json'); let raw = fs.readFileSync(statsPath, 'utf8'); if (raw.charCodeAt(0) === 0xFEFF) raw = raw.slice(1); const stats = JSON.parse(raw); const s = stats.summary; let changed = []; if (s.hooksRegistered !== 29) { s.hooksRegistered = 29; s.hooksUnregistered = 21; changed.push('W2: hooksRegistered→29'); } if (s.agentsOpus !== 6) { s.agentsOpus = 6; changed.push('W4a: agentsOpus→6'); } if (s.agentsSonnet !== 11) { s.agentsSonnet = 11; changed.push('W4b: agentsSonnet→11'); } if (changed.length) { stats.generated = new Date().toISOString(); fs.writeFileSync(statsPath, JSON.stringify(stats, null, 2), 'utf8'); console.log('W2+W4 FIXED:', changed.join(', ')); } else { console.log('W2+W4 SKIP: already correct'); } // W5: Fix fail-mode.js comment exit(1)→exit(2) const fmPath = path.join(ROOT, 'hooks', 'lib', 'fail-mode.js'); let fm = fs.readFileSync(fmPath, 'utf8'); const oldComment = "mode='enforce': 调用方应据此 process.exit(1)"; const newComment = "mode='enforce': 调用方应据此 process.exit(2)"; if (fm.includes(oldComment)) { fs.copyFileSync(fmPath, fmPath + '.bak'); fm = fm.replace(oldComment, newComment); fs.writeFileSync(fmPath, fm, 'utf8'); console.log('W5 FIXED: fail-mode.js comment exit(1)→exit(2)'); } else { console.log('W5 SKIP: already fixed or pattern not found'); } console.log('All patches applied.');