50 lines
1.9 KiB
JavaScript
50 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* 同步项目脱敏补丁 — 2026-04-21
|
|
*
|
|
* 问题: constitution/anti-arrogance.md:71 含硬编码绝对路径 C:\Users\leesu
|
|
* 修复: 替换为 ~ 和 <project-id> 占位
|
|
* 行为: 仅文档示例字符串变化, 无可执行代码
|
|
* 幂等: sentinel = 'CONSTITUTION_PATH_PORTABLE_2026_04_21'
|
|
*/
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const CLAUDE_ROOT = path.join(__dirname, '..', '..');
|
|
const TARGET = path.join(CLAUDE_ROOT, 'constitution', 'anti-arrogance.md');
|
|
const BACKUP = TARGET + '.bak.sync-portable';
|
|
const TMP = TARGET + '.tmp.sync-portable';
|
|
const SENTINEL = 'CONSTITUTION_PATH_PORTABLE_2026_04_21';
|
|
|
|
function main() {
|
|
if (!fs.existsSync(TARGET)) {
|
|
console.error('[patch-anti-arrogance] 不存在:', TARGET);
|
|
process.exit(1);
|
|
}
|
|
const before = fs.readFileSync(TARGET, 'utf8');
|
|
if (before.includes(SENTINEL)) {
|
|
console.log('[patch-anti-arrogance] 已打过补丁, 跳过');
|
|
process.exit(0);
|
|
}
|
|
const oldStr = '`cp C:\\Users\\leesu\\.claude\\projects\\C--Users-leesu\\memory\\feedback_anti_arrogance_constitution_0420.md C:\\Users\\leesu\\.claude\\constitution\\anti-arrogance.md`';
|
|
const newStr = '`cp ~/.claude/projects/<project-id>/memory/feedback_anti_arrogance_constitution_0420.md ~/.claude/constitution/anti-arrogance.md` <!-- ' + SENTINEL + ' -->';
|
|
|
|
if (!before.includes(oldStr)) {
|
|
console.error('[patch-anti-arrogance] 锚点未找到');
|
|
process.exit(2);
|
|
}
|
|
if (!fs.existsSync(BACKUP)) fs.copyFileSync(TARGET, BACKUP);
|
|
const after = before.replace(oldStr, newStr);
|
|
if (after === before || !after.includes(SENTINEL)) {
|
|
console.error('[patch-anti-arrogance] 替换失败');
|
|
process.exit(3);
|
|
}
|
|
fs.writeFileSync(TMP, after, 'utf8');
|
|
fs.renameSync(TMP, TARGET);
|
|
console.log('[patch-anti-arrogance] OK · 备份:', path.relative(CLAUDE_ROOT, BACKUP));
|
|
}
|
|
|
|
main();
|