- CLAUDE.md 升版至 V11.0:整合 P7/P9/P10 工作模式、12 人專家團隊、 委派鐵律、三條紅線(保留狙擊手模式精神) - .claude/hooks/:新增 8 個 Hook(momo-prod-guard / commit-quality / large-file-warner / mcp-health / audit-log / suggest-compact / cost-tracker / session-summary) - .claude/agents/:新增 11 個 Agent 定義(critic / debugger / db-expert / vuln-verifier / fullstack-engineer / planner / refactor-specialist / migration-engineer / onboarder / tool-expert / web-researcher) - .claude/settings.json:啟用 bypassPermissions + Hook 自動政策架構 - .gitignore:加入 settings.local.json 防止 Secret 意外 commit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
32 lines
1.4 KiB
JavaScript
32 lines
1.4 KiB
JavaScript
/**
|
||
* session-summary.js — Stop Hook
|
||
* 每次對話結束存快照(工作目錄 + git 狀態 + 最近 commits)。
|
||
*/
|
||
const fs = require('fs');
|
||
const os = require('os');
|
||
const path = require('path');
|
||
const crypto = require('crypto');
|
||
const { spawnSync } = require('child_process');
|
||
let d = '';
|
||
process.stdin.on('data', c => d += c);
|
||
process.stdin.on('end', () => {
|
||
try {
|
||
const sid = (process.env.CLAUDE_SESSION_ID || crypto.createHash('md5').update(process.cwd()).digest('hex').substring(0, 8)).replace(/[^a-zA-Z0-9_-]/g, '_').substring(0, 64);
|
||
const sessionsDir = path.join(os.homedir(), '.claude', 'sessions');
|
||
if (!fs.existsSync(sessionsDir)) fs.mkdirSync(sessionsDir, { recursive: true });
|
||
let entry = `\n## ${new Date().toLocaleTimeString()} — ${new Date().toLocaleDateString()}\n`;
|
||
entry += `\n**CWD:** ${process.cwd()}\n`;
|
||
try {
|
||
const gs = spawnSync('git', ['status', '--short'], { encoding: 'utf8', timeout: 3000 });
|
||
if (gs.stdout) entry += `\n**Git Status:**\n\`\`\`\n${gs.stdout}\`\`\`\n`;
|
||
} catch (e) {}
|
||
try {
|
||
const gl = spawnSync('git', ['log', '--oneline', '-5'], { encoding: 'utf8', timeout: 3000 });
|
||
if (gl.stdout) entry += `\n**Recent Commits:**\n\`\`\`\n${gl.stdout}\`\`\`\n`;
|
||
} catch (e) {}
|
||
const sessionFile = path.join(sessionsDir, `${new Date().toISOString().split('T')[0]}-${sid}.md`);
|
||
fs.appendFileSync(sessionFile, entry);
|
||
} catch (e) {}
|
||
process.stdout.write(d);
|
||
});
|