bookworm-smart-assistant/scripts/patches/patch-w3-log-rotator-extend.js
Bookworm Admin b7a8e29d21 release: v6.7.0 - OTA E2E test release
- 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)
2026-04-27 17:59:44 +08:00

41 lines
1.8 KiB
JavaScript

#!/usr/bin/env node
/**
* Patch W3: log-rotator 扩展覆盖范围
* - 修复 route-2- 正则要求紧跟 dash 的 bug (实际文件 route-2026-*)
* - 扩展匹配 ab-experiments / hook-timing / skill-outcome / pre-agent-gate 日 TTL
* 幂等: sentinel W3_LOG_EXTEND
*/
const fs = require('fs');
const path = require('path');
const TARGET = path.join(__dirname, '..', '..', 'hooks', 'log-rotator.js');
const SENTINEL = 'W3_LOG_EXTEND_v1';
function main() {
if (!fs.existsSync(TARGET)) { console.error('[patch-w3] missing target'); process.exit(2); }
const src = fs.readFileSync(TARGET, 'utf8');
if (src.includes(SENTINEL)) { console.log('[patch-w3] already applied (sentinel found), skip'); process.exit(0); }
const oldRe = /\/\^\(activity\|trace\|outcome\|compliance\|route-2\|security\|route-stats-daily\)-\/\.test\(f\)/;
if (!oldRe.test(src)) { console.error('[patch-w3] anchor not found, abort'); process.exit(3); }
// 新正则: 兼容 route-2026-XX-XX 格式 (route-\d{4}-);新增 ab-experiments / hook-timing / skill-outcome / pre-agent-gate
const patched = src.replace(
oldRe,
"/* " + SENTINEL + " */ (/^(activity|trace|outcome|compliance|security|route-stats-daily|ab-experiments|hook-timing|skill-outcome|pre-agent-gate)-?/.test(f) || /^route-\\d{4}-\\d{2}-\\d{2}\\.jsonl$/.test(f))"
);
if (patched === src) { console.error('[patch-w3] replace failed'); process.exit(4); }
// 备份 + 原子写
const bakDir = path.join(path.dirname(TARGET), 'archive');
if (!fs.existsSync(bakDir)) fs.mkdirSync(bakDir, { recursive: true });
const bak = path.join(bakDir, 'log-rotator.js.bak.w3.' + Date.now());
fs.writeFileSync(bak, src);
const tmp = TARGET + '.tmp.' + process.pid;
fs.writeFileSync(tmp, patched);
fs.renameSync(tmp, TARGET);
console.log('[patch-w3] applied. backup:', bak);
}
main();