bookworm-smart-assistant/scripts/patches/patch-feature-flags-version.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

64 lines
1.8 KiB
JavaScript

#!/usr/bin/env node
/**
* Feature-flags 版本同步补丁 — 2026-04-25 audit
*
* 目标: feature-flags.json.version 从 v6.5.1 升级到 v6.6.0-phase1-B
*
* 背景:
* stats-compiled.json 与 CLAUDE.md 已为 v6.6.0-phase1-B,
* feature-flags.json 仍停留在 v6.5.1 (self-auditor 报的 W3 衍生漂移)。
* 因 feature-flags.json 受 block-sensitive-files 保护,
* 必须通过补丁脚本 (feedback_patch_script_protocol.md) 执行。
*
* 幂等: 若版本已是目标版本则跳过。
* 安全: .bak + sentinel + 原子写 (tmp+rename)
*/
'use strict';
const fs = require('fs');
const path = require('path');
const TARGET = path.join(__dirname, '..', '..', 'feature-flags.json');
const TARGET_VERSION = 'v6.6.0-phase1-B';
function main() {
if (!fs.existsSync(TARGET)) {
console.error('[patch-ff] 目标不存在:', TARGET);
process.exit(1);
}
const raw = fs.readFileSync(TARGET, 'utf8');
let json;
try {
json = JSON.parse(raw);
} catch (e) {
console.error('[patch-ff] JSON 解析失败:', e.message);
process.exit(1);
}
if (json.version === TARGET_VERSION) {
console.log('[patch-ff] 已是目标版本', TARGET_VERSION, ',跳过');
process.exit(0);
}
const oldVersion = json.version;
// 备份
const bakPath = TARGET + '.bak.patch-ff-version.' + new Date().toISOString().replace(/[:.]/g, '-');
fs.writeFileSync(bakPath, raw, 'utf8');
// 修改
json.version = TARGET_VERSION;
const newRaw = JSON.stringify(json, null, 2) + '\n';
// 原子写
const tmp = TARGET + '.tmp.' + process.pid;
fs.writeFileSync(tmp, newRaw, 'utf8');
fs.renameSync(tmp, TARGET);
console.log('[patch-ff] 版本已同步:', oldVersion, '→', TARGET_VERSION);
console.log('[patch-ff] 备份:', path.basename(bakPath));
}
main();