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>
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
#!/usr/bin/env node
|
|
// 幂等补丁: 为 session-continuity-mcp 的 3 个 hook 添加 timeout: 5000
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const SETTINGS = path.join(process.env.HOME || process.env.USERPROFILE, '.claude', 'settings.json');
|
|
const SENTINEL = '__patch_session_continuity_timeout_v1';
|
|
const BAK = SETTINGS + '.bak-sct-' + Date.now();
|
|
|
|
const raw = fs.readFileSync(SETTINGS, 'utf8');
|
|
const cfg = JSON.parse(raw);
|
|
|
|
if (cfg[SENTINEL]) {
|
|
console.log('[SKIP] 补丁已应用');
|
|
process.exit(0);
|
|
}
|
|
|
|
fs.copyFileSync(SETTINGS, BAK);
|
|
console.log('[BAK]', BAK);
|
|
|
|
const TARGET = 'claude-session-continuity-mcp/dist/hooks/';
|
|
let patched = 0;
|
|
|
|
for (const [event, groups] of Object.entries(cfg.hooks || {})) {
|
|
for (const group of groups) {
|
|
for (const hook of (group.hooks || [])) {
|
|
if (hook.command && hook.command.includes(TARGET) && !hook.timeout) {
|
|
hook.timeout = 5000;
|
|
patched++;
|
|
console.log(`[PATCH] ${event}: +timeout 5000`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
cfg[SENTINEL] = new Date().toISOString();
|
|
fs.writeFileSync(SETTINGS, JSON.stringify(cfg, null, 2), 'utf8');
|
|
console.log(`[DONE] ${patched} hooks patched`);
|