bookworm-smart-assistant/scripts/patches/fix-lvp-persist-0427.js
Bookworm Admin 34f304881f fix: strip session-continuity-mcp hooks from Portable template
export.mjs now removes hooks referencing npm packages not included
in the Portable distribution (session-continuity-mcp).
Eliminates MODULE_NOT_FOUND errors on Portable installations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-27 22:15:39 +08:00

24 lines
1.0 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
// Fix: lastValidPrimary 未持久化到 route-state-current.json
// writeRouteState 只保存 6 个字段lastValidPrimary 被丢弃
// 导致图片继承链在跨 hook 调用时永远无法回退到上一个有效路由
const fs = require('fs');
const path = require('path');
const SENTINEL = '// LVP_PERSIST_FIX_v1';
const fp = path.join(__dirname, '..', 'route-state.js');
let code = fs.readFileSync(fp, 'utf8');
if (code.includes(SENTINEL)) { console.log('SKIP: already patched'); process.exit(0); }
const marker = 'domain: routing.domain || null,';
const idx = code.indexOf(marker);
if (idx === -1) { console.error('FAIL: cannot find domain field in writeRouteState'); process.exit(1); }
const insertPos = idx + marker.length;
const patch = `\n lastValidPrimary: routing.lastValidPrimary || null, ${SENTINEL}`;
fs.copyFileSync(fp, fp + '.bak');
code = code.slice(0, insertPos) + patch + code.slice(insertPos);
fs.writeFileSync(fp, code, 'utf8');
console.log('PATCHED: lastValidPrimary now persisted in route-state-current.json');