bookworm-smart-assistant/scripts/patches/patch-registry-hook-count-sync.js

28 lines
1.0 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
// 幂等补丁: 同步 SKILL-REGISTRY.md 钩子计数至实际磁盘值
const fs = require('fs');
const path = require('path');
const SENTINEL = '<!-- patch:hook-count-sync-v1 -->';
const registryPath = path.join(__dirname, '..', '..', 'SKILL-REGISTRY.md');
let content = fs.readFileSync(registryPath, 'utf8');
if (content.includes(SENTINEL)) {
console.log('[patch] already applied, skipping');
process.exit(0);
}
const oldPattern = /## 钩子清单 \(17 注册条目\/17 唯一文件 \+ 2 豁免disabled \+ 1 备用未注册 \+ 16 sub-hooks磁盘文件 34 个\)/;
const newLine = '## 钩子清单 (26 注册条目 + 24 备用未注册,磁盘文件 50 个)';
if (!oldPattern.test(content)) {
console.log('[patch] target string not found, may already be updated');
process.exit(0);
}
content = content.replace(oldPattern, newLine + ' ' + SENTINEL);
fs.writeFileSync(registryPath, content, 'utf8');
console.log('[patch] SKILL-REGISTRY.md hook count updated: 34→50 disk, 17→26 registered');