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:
82
scripts/hooks/session-end.js
Normal file
82
scripts/hooks/session-end.js
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Stop Hook (Session End) - Persist learnings when session ends
|
||||
*
|
||||
* Cross-platform (Windows, macOS, Linux)
|
||||
*
|
||||
* Runs when Claude session ends. Creates/updates session log file
|
||||
* with timestamp for continuity tracking.
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const {
|
||||
getSessionsDir,
|
||||
getDateString,
|
||||
getTimeString,
|
||||
ensureDir,
|
||||
readFile,
|
||||
writeFile,
|
||||
replaceInFile,
|
||||
log
|
||||
} = require('../lib/utils');
|
||||
|
||||
async function main() {
|
||||
const sessionsDir = getSessionsDir();
|
||||
const today = getDateString();
|
||||
const sessionFile = path.join(sessionsDir, `${today}-session.tmp`);
|
||||
|
||||
ensureDir(sessionsDir);
|
||||
|
||||
const currentTime = getTimeString();
|
||||
|
||||
// If session file exists for today, update the end time
|
||||
if (fs.existsSync(sessionFile)) {
|
||||
const success = replaceInFile(
|
||||
sessionFile,
|
||||
/\*\*Last Updated:\*\*.*/,
|
||||
`**Last Updated:** ${currentTime}`
|
||||
);
|
||||
|
||||
if (success) {
|
||||
log(`[SessionEnd] Updated session file: ${sessionFile}`);
|
||||
}
|
||||
} else {
|
||||
// Create new session file with template
|
||||
const template = `# Session: ${today}
|
||||
**Date:** ${today}
|
||||
**Started:** ${currentTime}
|
||||
**Last Updated:** ${currentTime}
|
||||
|
||||
---
|
||||
|
||||
## Current State
|
||||
|
||||
[Session context goes here]
|
||||
|
||||
### Completed
|
||||
- [ ]
|
||||
|
||||
### In Progress
|
||||
- [ ]
|
||||
|
||||
### Notes for Next Session
|
||||
-
|
||||
|
||||
### Context to Load
|
||||
\`\`\`
|
||||
[relevant files]
|
||||
\`\`\`
|
||||
`;
|
||||
|
||||
writeFile(sessionFile, template);
|
||||
log(`[SessionEnd] Created session file: ${sessionFile}`);
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
main().catch(err => {
|
||||
console.error('[SessionEnd] Error:', err.message);
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in New Issue
Block a user