- VERSION file as authoritative version source - export.mjs reads VERSION with package.json fallback - bw-ota.ps1 DryRun mode for safe testing - auto-setup.ps1 bumped to v3.2.0 (Phase 8 OTA)
67 lines
2.3 KiB
JavaScript
67 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* L2 mutual_exclusion 字段 loader 修复 (2026-04-25)
|
|
* route-analyzer.js loadDisambiguationRules() 追加 mutual_exclusion 字段
|
|
*
|
|
* 当前 loader 仅复制 {id, trigger, boost, penalty, weight},丢弃 mutual_exclusion
|
|
* 修复后: 追加 mutual_exclusion: r.mutual_exclusion 字段,激活互斥消解逻辑
|
|
*
|
|
* 幂等: 若已包含 mutual_exclusion 则跳过
|
|
* 备份: .bak.l2-mutual-exclusion.<ISO>
|
|
* sentinel: PATCH-L2-MUTUAL-EXCLUSION-LOADER-APPLIED
|
|
*/
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const TARGET = path.join(__dirname, '..', 'route-analyzer.js');
|
|
const SENTINEL = 'PATCH-L2-MUTUAL-EXCLUSION-LOADER-APPLIED';
|
|
const OLD_STR = ' boost: r.boost,\n penalty: r.penalty,\n weight: r.weight,\n }));';
|
|
const NEW_STR = ' boost: r.boost,\n penalty: r.penalty,\n weight: r.weight,\n mutual_exclusion: r.mutual_exclusion,\n }));';
|
|
|
|
function main() {
|
|
if (!fs.existsSync(TARGET)) {
|
|
console.error('[L2] route-analyzer.js 不存在:', TARGET);
|
|
process.exit(1);
|
|
}
|
|
const content = fs.readFileSync(TARGET, 'utf8');
|
|
|
|
// 幂等检查
|
|
if (content.includes(SENTINEL) || content.includes('mutual_exclusion: r.mutual_exclusion')) {
|
|
console.log('[L2] 已是最新状态,跳过');
|
|
process.exit(0);
|
|
}
|
|
|
|
if (!content.includes(OLD_STR)) {
|
|
console.error('[L2] 未找到目标代码段,可能已被修改');
|
|
// 输出上下文以便诊断
|
|
const idx = content.indexOf('weight: r.weight');
|
|
if (idx !== -1) {
|
|
console.error('[L2] 找到 weight: r.weight 上下文:\n', content.slice(idx - 50, idx + 100));
|
|
}
|
|
process.exit(1);
|
|
}
|
|
|
|
// 备份
|
|
const bak = TARGET + '.bak.l2-mutual-exclusion.' + new Date().toISOString().replace(/[:.]/g, '-');
|
|
fs.copyFileSync(TARGET, bak);
|
|
console.log('[L2] 备份:', bak);
|
|
|
|
// 替换
|
|
const newContent = content.replace(OLD_STR, NEW_STR);
|
|
|
|
// 原子写入 (tmp + rename)
|
|
const tmp = TARGET + '.l2.tmp.' + process.pid;
|
|
fs.writeFileSync(tmp, newContent, 'utf8');
|
|
fs.renameSync(tmp, TARGET);
|
|
|
|
console.log('[L2] 成功: 追加 mutual_exclusion 字段到 loadDisambiguationRules()');
|
|
console.log('[L2] ' + SENTINEL);
|
|
}
|
|
|
|
try { main(); } catch (e) {
|
|
console.error('[L2] 异常:', e.message);
|
|
process.exit(1);
|
|
}
|