sumulige-claude 1.0.11 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,164 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Session Save Hook - Save conversation context to file
4
+ *
5
+ * Triggered after each conversation turn
6
+ * Saves conversation history, context, and state
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+
12
+ const PROJECT_DIR = process.env.CLAUDE_PROJECT_DIR || process.cwd();
13
+ const SESSIONS_DIR = path.join(PROJECT_DIR, '.claude', 'sessions');
14
+ const MEMORY_FILE = path.join(PROJECT_DIR, '.claude', 'MEMORY.md');
15
+
16
+ // Ensure sessions directory exists
17
+ if (!fs.existsSync(SESSIONS_DIR)) {
18
+ fs.mkdirSync(SESSIONS_DIR, { recursive: true });
19
+ }
20
+
21
+ /**
22
+ * Generate session filename
23
+ */
24
+ function getSessionFilename() {
25
+ const now = new Date();
26
+ const date = now.toISOString().split('T')[0];
27
+ const time = now.toTimeString().split(' ')[0].replace(/:/g, '-');
28
+ return `session_${date}_${time}.md`;
29
+ }
30
+
31
+ /**
32
+ * Save session context
33
+ */
34
+ function saveSession(context) {
35
+ const filename = getSessionFilename();
36
+ const filepath = path.join(SESSIONS_DIR, filename);
37
+
38
+ const content = `# Session - ${new Date().toISOString()}
39
+
40
+ > Type: ${context.type || 'chat'}
41
+ > Model: ${context.model || 'unknown'}
42
+ > Duration: ${context.duration || 'unknown'}
43
+
44
+ ---
45
+
46
+ ## Summary
47
+
48
+ ${context.summary || 'No summary provided'}
49
+
50
+ ---
51
+
52
+ ## Context
53
+
54
+ \`\`\`json
55
+ ${JSON.stringify(context.metadata || {}, null, 2)}
56
+ \`\`\`
57
+
58
+ ---
59
+
60
+ ## Key Points
61
+
62
+ ${(context.keyPoints || []).map((p, i) => `${i + 1}. ${p}`).join('\n')}
63
+
64
+ ---
65
+
66
+ ## Artifacts
67
+
68
+ ${(context.artifacts || []).map(a => `- ${a}`).join('\n') || 'None'}
69
+
70
+ ---
71
+
72
+ ## Next Steps
73
+
74
+ ${context.nextSteps || 'None'}
75
+
76
+ ---
77
+
78
+ *Session saved at: ${new Date().toISOString()}*
79
+ `;
80
+
81
+ fs.writeFileSync(filepath, content, 'utf-8');
82
+
83
+ // Update sessions index
84
+ updateSessionsIndex();
85
+
86
+ return filename;
87
+ }
88
+
89
+ /**
90
+ * Update sessions index
91
+ */
92
+ function updateSessionsIndex() {
93
+ const files = fs.readdirSync(SESSIONS_DIR)
94
+ .filter(f => f.endsWith('.md'))
95
+ .sort()
96
+ .reverse();
97
+
98
+ const indexPath = path.join(SESSIONS_DIR, 'INDEX.md');
99
+
100
+ let content = `# Sessions Index
101
+
102
+ > Total sessions: ${files.length}
103
+ > Last updated: ${new Date().toISOString()}
104
+
105
+ ---
106
+
107
+ ## Recent Sessions
108
+
109
+ ${files.slice(0, 20).map(f => {
110
+ const filepath = path.join(SESSIONS_DIR, f);
111
+ const stat = fs.statSync(filepath);
112
+ return `- [${f}](${f}) - ${stat.mtime.toISOString()}`;
113
+ }).join('\n')}
114
+
115
+ ---
116
+ `;
117
+
118
+ fs.writeFileSync(indexPath, content, 'utf-8');
119
+ }
120
+
121
+ /**
122
+ * Update MEMORY.md with latest context
123
+ */
124
+ function updateMemory(context) {
125
+ const timestamp = new Date().toISOString();
126
+
127
+ let content = '';
128
+
129
+ if (fs.existsSync(MEMORY_FILE)) {
130
+ content = fs.readFileSync(MEMORY_FILE, 'utf-8');
131
+ }
132
+
133
+ // Check if we need to add a new entry
134
+ const newEntry = `\n## ${timestamp.split('T')[0]}\n\n${
135
+ context.summary || context.keyPoints?.join('\n') || 'No details'
136
+ }\n`;
137
+
138
+ // Keep only last 7 days
139
+ const entries = content.split('## ').slice(1, 8);
140
+ content = '# Memory\n\n<!-- Project memory updated by AI -->\n' +
141
+ '## ' + entries.join('## ') + newEntry;
142
+
143
+ fs.writeFileSync(MEMORY_FILE, content, 'utf-8');
144
+ }
145
+
146
+ // Main execution
147
+ if (require.main === module) {
148
+ const args = process.argv.slice(2);
149
+
150
+ if (args[0] === '--save' && args[1]) {
151
+ const contextData = JSON.parse(fs.readFileSync(args[1], 'utf-8'));
152
+ const filename = saveSession(contextData);
153
+ console.log(`✅ Session saved: ${filename}`);
154
+
155
+ if (contextData.addToMemory !== false) {
156
+ updateMemory(contextData);
157
+ console.log(`✅ Memory updated`);
158
+ }
159
+ }
160
+ }
161
+
162
+ exports.saveSession = saveSession;
163
+ exports.updateMemory = updateMemory;
164
+ exports.updateSessionsIndex = updateSessionsIndex;