mirror of
https://github.com/sweetwisdom/everything-claude-code-zh.git
synced 2026-03-22 06:20:10 +00:00
feat: cross-platform support with Node.js scripts
- Rewrite all bash hooks to Node.js for Windows/macOS/Linux compatibility - Add package manager auto-detection (npm, pnpm, yarn, bun) - Add scripts/lib/ with cross-platform utilities - Add /setup-pm command for package manager configuration - Add comprehensive test suite (62 tests) Co-authored-by: zerx-lab
This commit is contained in:
48
scripts/hooks/pre-compact.js
Normal file
48
scripts/hooks/pre-compact.js
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* PreCompact Hook - Save state before context compaction
|
||||
*
|
||||
* Cross-platform (Windows, macOS, Linux)
|
||||
*
|
||||
* Runs before Claude compacts context, giving you a chance to
|
||||
* preserve important state that might get lost in summarization.
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const {
|
||||
getSessionsDir,
|
||||
getDateTimeString,
|
||||
getTimeString,
|
||||
findFiles,
|
||||
ensureDir,
|
||||
appendFile,
|
||||
log
|
||||
} = require('../lib/utils');
|
||||
|
||||
async function main() {
|
||||
const sessionsDir = getSessionsDir();
|
||||
const compactionLog = path.join(sessionsDir, 'compaction-log.txt');
|
||||
|
||||
ensureDir(sessionsDir);
|
||||
|
||||
// Log compaction event with timestamp
|
||||
const timestamp = getDateTimeString();
|
||||
appendFile(compactionLog, `[${timestamp}] Context compaction triggered\n`);
|
||||
|
||||
// If there's an active session file, note the compaction
|
||||
const sessions = findFiles(sessionsDir, '*.tmp');
|
||||
|
||||
if (sessions.length > 0) {
|
||||
const activeSession = sessions[0].path;
|
||||
const timeStr = getTimeString();
|
||||
appendFile(activeSession, `\n---\n**[Compaction occurred at ${timeStr}]** - Context was summarized\n`);
|
||||
}
|
||||
|
||||
log('[PreCompact] State saved before compaction');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('[PreCompact] Error:', err.message);
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in New Issue
Block a user