bookworm-smart-assistant/scripts/patches/patch-r5-claudemd-doc.js

39 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

#!/usr/bin/env node
/**
* patch-r5-claudemd-doc.js · 2026-04-26
*
* R5: CLAUDE.md §上下文管理 追加 Agent 隔离软门控说明
*
* 幂等: sentinel "Agent 隔离软门控"
*/
'use strict';
const fs = require('fs');
const path = require('path');
const TARGET = path.join(__dirname, '..', '..', 'CLAUDE.md');
const SENTINEL = 'Agent 隔离软门控';
const ANCHOR = '- 重型任务(代码审计/系统自检)优先委托 Agent 子进程(隔离上下文)';
const NEW = '- 重型任务(代码审计/系统自检)优先委托 Agent 子进程(隔离上下文)— R5 **Agent 隔离软门控** 已自动检测 Bash 循环 (≥6 项)/seq/&&-链 (≥6) 与短期 Write/Edit 累计 (90s 内 ≥5 次), 触发时通过 systemMessage 提示改派 Agent';
function main() {
const src = fs.readFileSync(TARGET, 'utf8');
if (src.includes(SENTINEL)) {
console.log('[r5-doc] already applied, skip');
return;
}
if (!src.includes(ANCHOR)) {
console.error('[r5-doc] anchor not found, manual review needed');
process.exit(1);
}
const next = src.replace(ANCHOR, NEW);
const bak = TARGET + '.bak.r5doc.' + Date.now();
fs.copyFileSync(TARGET, bak);
const tmp = TARGET + '.tmp.' + process.pid;
fs.writeFileSync(tmp, next, 'utf8');
fs.renameSync(tmp, TARGET);
console.log('[r5-doc] OK, bak:', path.basename(bak));
}
main();