claude-mem 3.2.7 → 3.3.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.
- package/claude-mem +0 -0
- package/hooks/session-end.js +38 -3
- package/hooks/session-start.js +13 -6
- package/package.json +1 -1
package/claude-mem
CHANGED
|
Binary file
|
package/hooks/session-end.js
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Session End Hook -
|
|
5
|
-
* Make it work first. No validation. Just execution.
|
|
4
|
+
* Session End Hook - Handles session end events including /clear
|
|
6
5
|
*/
|
|
7
6
|
|
|
8
7
|
import { loadCliCommand } from './shared/config-loader.js';
|
|
8
|
+
import { execSync } from 'child_process';
|
|
9
|
+
import { join } from 'path';
|
|
10
|
+
import { homedir } from 'os';
|
|
11
|
+
import { existsSync, readFileSync } from 'fs';
|
|
9
12
|
|
|
10
13
|
const cliCommand = loadCliCommand();
|
|
11
14
|
|
|
15
|
+
// Check if save-on-clear is enabled
|
|
16
|
+
function isSaveOnClearEnabled() {
|
|
17
|
+
const settingsPath = join(homedir(), '.claude-mem', 'settings.json');
|
|
18
|
+
if (existsSync(settingsPath)) {
|
|
19
|
+
try {
|
|
20
|
+
const settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
|
|
21
|
+
return settings.saveMemoriesOnClear === true;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
12
29
|
// Read input
|
|
13
30
|
let input = '';
|
|
14
31
|
process.stdin.on('data', chunk => {
|
|
@@ -18,6 +35,24 @@ process.stdin.on('data', chunk => {
|
|
|
18
35
|
process.stdin.on('end', async () => {
|
|
19
36
|
const data = JSON.parse(input);
|
|
20
37
|
|
|
21
|
-
//
|
|
38
|
+
// Check if this is a clear event and save-on-clear is enabled
|
|
39
|
+
if (data.reason === 'clear' && isSaveOnClearEnabled()) {
|
|
40
|
+
console.error('🧠 Saving memories before clearing context...');
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
// Use the CLI to compress current transcript
|
|
44
|
+
execSync(`${cliCommand} compress --output ${homedir()}/.claude-mem/archives`, {
|
|
45
|
+
stdio: 'inherit',
|
|
46
|
+
env: { ...process.env, CLAUDE_MEM_SILENT: 'true' }
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
console.error('✅ Memories saved successfully');
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error('[session-end] Failed to save memories:', error.message);
|
|
52
|
+
// Don't block the clear operation if memory saving fails
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Always continue
|
|
22
57
|
console.log(JSON.stringify({ continue: true }));
|
|
23
58
|
});
|
package/hooks/session-start.js
CHANGED
|
@@ -44,9 +44,10 @@ process.stdin.on('end', async () => {
|
|
|
44
44
|
process.exit(0);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
// Extract project name from current working directory
|
|
48
|
-
const
|
|
49
|
-
|
|
47
|
+
// Extract project name from current working directory and sanitize
|
|
48
|
+
const rawProjectName = path.basename(process.cwd());
|
|
49
|
+
const projectName = rawProjectName.replace(/-/g, '_');
|
|
50
|
+
debugLog('Extracted project name', { rawProjectName, projectName });
|
|
50
51
|
|
|
51
52
|
// Load context using standardized CLI execution helper
|
|
52
53
|
const contextResult = await executeCliCommand(cliCommand, [
|
|
@@ -142,9 +143,15 @@ process.stdin.on('end', async () => {
|
|
|
142
143
|
function extractProjectName(transcriptPath) {
|
|
143
144
|
if (!transcriptPath) return null;
|
|
144
145
|
|
|
145
|
-
// Look for
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
// Look for project pattern: /path/to/PROJECT_NAME/.claude/
|
|
147
|
+
// Need to get PROJECT_NAME, not the parent directory
|
|
148
|
+
const parts = transcriptPath.split('/');
|
|
149
|
+
const claudeIndex = parts.indexOf('.claude');
|
|
150
|
+
|
|
151
|
+
if (claudeIndex > 0) {
|
|
152
|
+
// Get the directory immediately before .claude
|
|
153
|
+
return parts[claudeIndex - 1];
|
|
154
|
+
}
|
|
148
155
|
|
|
149
156
|
// Fall back to directory containing the transcript
|
|
150
157
|
const dir = path.dirname(transcriptPath);
|