bookworm-smart-assistant/scripts/patches/patch-r1-batch-checkpoint-rule.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

42 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* patch-r1-batch-checkpoint-rule.js · 2026-04-26
*
* R1: 批量任务切片 + 增量 checkpoint 规则注入 CLAUDE.md §上下文管理
* 触发场景: >5 个独立子项的 Write/Edit/Bash 批量操作
* 收益: context 增长从 O(N) 降到 O(N/3), 中断可从 .bookworm-progress.md 恢复
*
* 幂等: sentinel "批量任务切片"
*/
'use strict';
const fs = require('fs');
const path = require('path');
const TARGET = path.join(__dirname, '..', '..', 'CLAUDE.md');
const SENTINEL = '批量任务切片';
const OLD_LINE = '- Compact at 60% context usage, do not wait until critical';
const NEW_LINES = `- Compact at 60% context usage, do not wait until critical
- **批量任务切片**>5 个独立子项的 Write/Edit/Bash 操作):每 3 项为一批,每批结束后 (a) 追加进度到 \`<cwd>/.bookworm-progress.md\` (格式 \`YYYY-MM-DDTHH:mm | batch N/M | desc\`)(b) 仅回复一行 \`[batch N/M ✓ desc]\`,不复述生成内容;中断后从 progress 文件恢复`;
function main() {
const src = fs.readFileSync(TARGET, 'utf8');
if (src.includes(SENTINEL)) {
console.log('[r1] already applied, skip');
return;
}
if (!src.includes(OLD_LINE)) {
console.error('[r1] anchor line not found, manual review needed');
process.exit(1);
}
const next = src.replace(OLD_LINE, NEW_LINES);
const bak = TARGET + '.bak.r1.' + Date.now();
fs.copyFileSync(TARGET, bak);
const tmp = TARGET + '.tmp.' + process.pid;
fs.writeFileSync(tmp, next, 'utf8');
fs.renameSync(tmp, TARGET);
console.log('[r1] OK, bak:', path.basename(bak));
}
main();