bookworm-smart-assistant/scripts/patches/patch-x09-cjk-korean-range.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
/**
* patch-x09-cjk-korean-range.js
* 扩展 context-pressure-monitor.js CJK 检测范围: 0xE3-0xE9 0xE4-0xED
* 包含韩文音节 0xEA-0xED + 修正 0xE3 (日文平假名等非 CJK 汉字)
*
* 幂等: SENTINEL 标记
*/
'use strict';
const fs = require('fs');
const path = require('path');
const SENTINEL = '[PATCH-X09-CJK-KOREAN]';
const TARGET = path.join(__dirname, '..', '..', 'hooks', 'context-pressure-monitor.js');
if (!fs.existsSync(TARGET)) { console.log('SKIP: target not found'); process.exit(0); }
let src = fs.readFileSync(TARGET, 'utf8');
if (src.includes(SENTINEL)) { console.log('SKIP: already patched'); process.exit(0); }
const old = " if (b >= 0xE3 && b <= 0xE9) cjk += 3;";
const replacement = " if (b >= 0xE4 && b <= 0xED) cjk += 3; // " + SENTINEL;
if (!src.includes(old)) {
console.error('FAIL: old CJK range not found');
process.exit(1);
}
src = src.replace(old, replacement);
const tmp = TARGET + '.tmp.' + process.pid;
fs.writeFileSync(tmp, src, 'utf8');
fs.renameSync(tmp, TARGET);
console.log('OK: X09 CJK range extended to 0xE4-0xED (CJK Unified + Korean Syllables)');