claude-mem 3.0.5 → 3.1.6

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.
Files changed (79) hide show
  1. package/claude-mem +0 -0
  2. package/dist/{cli.js → bin/cli.js} +40 -11
  3. package/dist/commands/compress.js +13 -65
  4. package/dist/commands/hooks.d.ts +19 -0
  5. package/dist/commands/hooks.js +102 -0
  6. package/dist/commands/install.js +523 -215
  7. package/dist/commands/load-context.js +73 -87
  8. package/dist/commands/logs.js +26 -10
  9. package/dist/commands/setup.d.ts +23 -0
  10. package/dist/commands/setup.js +304 -0
  11. package/dist/commands/status.js +18 -41
  12. package/dist/commands/uninstall.js +31 -29
  13. package/dist/constants.d.ts +66 -307
  14. package/dist/constants.js +49 -368
  15. package/dist/core/compression/TranscriptCompressor.d.ts +83 -0
  16. package/dist/core/compression/TranscriptCompressor.js +561 -0
  17. package/dist/core/orchestration/PromptOrchestrator.d.ts +165 -0
  18. package/dist/core/orchestration/PromptOrchestrator.js +182 -0
  19. package/dist/prompts/constants.d.ts +126 -0
  20. package/dist/prompts/constants.js +161 -0
  21. package/dist/prompts/index.d.ts +10 -0
  22. package/dist/prompts/index.js +11 -0
  23. package/dist/prompts/templates/analysis/AnalysisTemplates.d.ts +13 -0
  24. package/dist/prompts/templates/analysis/AnalysisTemplates.js +94 -0
  25. package/dist/prompts/templates/context/ContextTemplates.d.ts +95 -0
  26. package/dist/prompts/templates/context/ContextTemplates.js +324 -0
  27. package/dist/prompts/templates/hooks/HookTemplates.d.ts +175 -0
  28. package/dist/prompts/templates/hooks/HookTemplates.js +394 -0
  29. package/dist/prompts/templates/hooks/HookTemplates.test.d.ts +7 -0
  30. package/dist/prompts/templates/hooks/HookTemplates.test.js +127 -0
  31. package/dist/shared/config-manager.d.ts +126 -0
  32. package/dist/shared/config-manager.js +269 -0
  33. package/dist/{config.d.ts → shared/config.d.ts} +0 -2
  34. package/dist/{config.js → shared/config.js} +1 -3
  35. package/dist/{error-handler.d.ts → shared/error-handler.d.ts} +5 -0
  36. package/dist/{error-handler.js → shared/error-handler.js} +10 -0
  37. package/dist/shared/paths.d.ts +28 -0
  38. package/dist/{utils/PathResolver.js → shared/paths.js} +23 -1
  39. package/dist/{types.d.ts → shared/types.d.ts} +14 -21
  40. package/dist/storage/adapters/chroma-mcp-adapter.d.ts +62 -0
  41. package/dist/storage/adapters/chroma-mcp-adapter.js +92 -0
  42. package/dist/{utils → storage/clients}/mcp-client.d.ts +4 -4
  43. package/dist/{utils → storage/clients}/mcp-client.js +7 -7
  44. package/hooks/pre-compact.js +65 -199
  45. package/hooks/session-end.js +13 -160
  46. package/hooks/session-start.js +136 -60
  47. package/hooks/shared/config-loader.js +3 -11
  48. package/hooks/shared/hook-helpers.js +230 -0
  49. package/package.json +1 -1
  50. package/.mcp.json +0 -11
  51. package/dist/commands/migrate.d.ts +0 -9
  52. package/dist/commands/migrate.js +0 -225
  53. package/dist/mcp-server-cli.d.ts +0 -34
  54. package/dist/mcp-server-cli.js +0 -158
  55. package/dist/mcp-server.d.ts +0 -103
  56. package/dist/mcp-server.js +0 -301
  57. package/dist/utils/HookDetector.d.ts +0 -64
  58. package/dist/utils/HookDetector.js +0 -213
  59. package/dist/utils/PathResolver.d.ts +0 -16
  60. package/dist/utils/SettingsManager.d.ts +0 -63
  61. package/dist/utils/SettingsManager.js +0 -133
  62. package/dist/utils/TranscriptCompressor.d.ts +0 -157
  63. package/dist/utils/TranscriptCompressor.js +0 -554
  64. package/dist/utils/common.d.ts +0 -29
  65. package/dist/utils/common.js +0 -14
  66. package/dist/utils/error-utils.d.ts +0 -93
  67. package/dist/utils/error-utils.js +0 -238
  68. package/dist/utils/index.d.ts +0 -19
  69. package/dist/utils/index.js +0 -26
  70. package/dist/utils/mcp-client-factory.d.ts +0 -51
  71. package/dist/utils/mcp-client-factory.js +0 -115
  72. package/dist/utils/memory-mcp-client.d.ts +0 -135
  73. package/dist/utils/memory-mcp-client.js +0 -490
  74. package/dist/utils/weaviate-mcp-adapter.d.ts +0 -131
  75. package/dist/utils/weaviate-mcp-adapter.js +0 -483
  76. /package/dist/{cli.d.ts → bin/cli.d.ts} +0 -0
  77. /package/dist/{utils → shared}/logger.d.ts +0 -0
  78. /package/dist/{utils → shared}/logger.js +0 -0
  79. /package/dist/{types.js → shared/types.js} +0 -0
package/claude-mem CHANGED
Binary file
@@ -3,14 +3,14 @@
3
3
  // CLI Dependencies and Imports Setup
4
4
  // Natural pattern: Import what you need before using it
5
5
  import { Command } from 'commander';
6
- import { PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_DESCRIPTION } from './config.js';
6
+ import { PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_DESCRIPTION } from '../shared/config.js';
7
7
  // Import command handlers
8
- import { compress } from './commands/compress.js';
9
- import { install } from './commands/install.js';
10
- import { uninstall } from './commands/uninstall.js';
11
- import { status } from './commands/status.js';
12
- import { logs } from './commands/logs.js';
13
- import { loadContext } from './commands/load-context.js';
8
+ import { compress } from '../commands/compress.js';
9
+ import { install } from '../commands/install.js';
10
+ import { uninstall } from '../commands/uninstall.js';
11
+ import { status } from '../commands/status.js';
12
+ import { logs } from '../commands/logs.js';
13
+ import { loadContext } from '../commands/load-context.js';
14
14
  const program = new Command();
15
15
  // </Block> =======================================
16
16
  // <Block> 1.2 ====================================
@@ -40,8 +40,12 @@ program
40
40
  program
41
41
  .command('install')
42
42
  .description('Install Claude Code hooks for automatic compression')
43
- .option('--global', 'Install globally (default)')
43
+ .option('--user', 'Install for current user (default)')
44
44
  .option('--project', 'Install for current project only')
45
+ .option('--local', 'Install to custom local directory')
46
+ .option('--path <path>', 'Custom installation path (with --local)')
47
+ .option('--timeout <ms>', 'Hook execution timeout in milliseconds', '180000')
48
+ .option('--skip-mcp', 'Skip Chroma MCP server installation')
45
49
  .option('--force', 'Force installation even if already installed')
46
50
  .action(install);
47
51
  // </Block> =======================================
@@ -52,9 +56,9 @@ program
52
56
  program
53
57
  .command('uninstall')
54
58
  .description('Remove Claude Code hooks')
55
- .option('--global', 'Remove from global settings')
59
+ .option('--user', 'Remove from user settings (default)')
56
60
  .option('--project', 'Remove from project settings')
57
- .option('--all', 'Remove from both global and project settings')
61
+ .option('--all', 'Remove from both user and project settings')
58
62
  .action(uninstall);
59
63
  // </Block> =======================================
60
64
  // <Block> 1.6 ====================================
@@ -92,7 +96,32 @@ program
92
96
  .option('--format <type>', 'Output format: json, session-start, or default')
93
97
  .action(loadContext);
94
98
  // </Block> =======================================
95
- // <Block> 1.9 ====================================
99
+ // <Block> 1.10 ===================================
100
+ // Hook Commands for Binary Distribution
101
+ // Internal commands called by hook wrappers
102
+ program
103
+ .command('hook:pre-compact', { hidden: true })
104
+ .description('Internal pre-compact hook handler')
105
+ .action(async () => {
106
+ const { preCompactHook } = await import('../commands/hooks.js');
107
+ await preCompactHook();
108
+ });
109
+ program
110
+ .command('hook:session-start', { hidden: true })
111
+ .description('Internal session-start hook handler')
112
+ .action(async () => {
113
+ const { sessionStartHook } = await import('../commands/hooks.js');
114
+ await sessionStartHook();
115
+ });
116
+ program
117
+ .command('hook:session-end', { hidden: true })
118
+ .description('Internal session-end hook handler')
119
+ .action(async () => {
120
+ const { sessionEndHook } = await import('../commands/hooks.js');
121
+ await sessionEndHook();
122
+ });
123
+ // </Block> =======================================
124
+ // <Block> 1.11 ===================================
96
125
  // CLI Execution
97
126
  // Natural pattern: After defining all commands, parse and execute
98
127
  // Parse arguments and execute
@@ -1,79 +1,27 @@
1
- import { existsSync } from 'fs';
2
- import { dirname, basename } from 'path';
3
- import { fileURLToPath } from 'url';
4
- const __filename = fileURLToPath(import.meta.url);
5
- const __dirname = dirname(__filename);
1
+ import { basename } from 'path';
2
+ import { createLoadingMessage, createCompletionMessage, createOperationSummary, createUserFriendlyError } from '../prompts/templates/context/ContextTemplates.js';
6
3
  export async function compress(transcript, options = {}) {
7
- // <Block> 1.1 ====================================
8
- // Guard clause - early exit for missing transcript parameter
4
+ console.log(createLoadingMessage('compressing'));
9
5
  if (!transcript) {
10
- console.error(' Transcript file path is required');
11
- process.exit(1);
12
- }
13
- // </Block> =======================================
14
- // <Block> 1.2 ====================================
15
- // File existence validation with early exit
16
- if (!existsSync(transcript)) {
17
- console.error(`❌ Transcript file not found: ${transcript}`);
18
- process.exit(1);
19
- }
20
- // </Block> =======================================
21
- console.log(`🗜️ Compressing transcript: ${transcript}`);
22
- // <Block> 1.3 ====================================
23
- // Dry run conditional - acceptable early return
24
- if (options.dryRun) {
25
- console.log('📋 Dry run mode - no files will be written');
6
+ console.log(createUserFriendlyError('Compression', 'No transcript file provided', 'Please provide a path to a transcript file'));
26
7
  return;
27
8
  }
28
- // </Block> =======================================
29
- // <Block> 1.4 ====================================
30
- // Main try-catch block for compression processing
31
9
  try {
32
- // Import TranscriptCompressor dynamically to ensure it's available
33
- const { TranscriptCompressor } = await import('../utils/TranscriptCompressor.js');
34
- // Create compressor instance
10
+ const startTime = Date.now();
11
+ // Import and run compression
12
+ const { TranscriptCompressor } = await import('../core/compression/TranscriptCompressor.js');
35
13
  const compressor = new TranscriptCompressor({
36
14
  verbose: options.verbose || false
37
15
  });
38
- // Extract session ID from transcript filename if not provided
39
16
  const sessionId = options.sessionId || basename(transcript, '.jsonl');
40
- // <Block> 1.5 ====================================
41
- // Verbose logging conditional
42
- if (options.verbose) {
43
- console.log(`📊 Starting compression with session ID: ${sessionId}`);
44
- }
45
- // </Block> =======================================
46
- // Perform compression
47
17
  const archivePath = await compressor.compress(transcript, sessionId);
48
- console.log('✅ Compression completed successfully');
49
- console.log(`📦 Archive created: ${archivePath}`);
50
- // <Block> 1.6 ====================================
51
- // Output path conditional - informational logging
52
- if (options.output && options.output !== dirname(archivePath)) {
53
- console.log(`📂 Output directory: ${options.output} (archive location may differ)`);
54
- }
55
- // </Block> =======================================
18
+ const duration = Date.now() - startTime;
19
+ console.log(createCompletionMessage('Compression', undefined, `Session archived as ${basename(archivePath)}`));
20
+ console.log(createOperationSummary('compress', { count: 1, duration, details: `Session: ${sessionId}` }));
56
21
  }
57
22
  catch (error) {
58
- const err = error;
59
- console.error('Compression failed:', err.message);
60
- if (options.verbose) {
61
- console.error('Stack trace:', err.stack);
62
- }
63
- // <Block> 1.7 ====================================
64
- // Error message customization - natural help system
65
- if (err.message.includes('Claude Code executable not found')) {
66
- console.error('💡 Hint: Make sure Claude Code is installed and accessible in your PATH');
67
- console.error(' Or set CLAUDE_CODE_PATH environment variable');
68
- }
69
- else if (err.message.includes('JWT_SECRET')) {
70
- console.error('💡 Hint: Make sure JWT_SECRET is set in your MCP configuration');
71
- }
72
- else if (err.message.includes('No summaries extracted')) {
73
- console.error('💡 Hint: The transcript may be too short or not contain analyzable content');
74
- }
75
- // </Block> =======================================
76
- process.exit(1);
23
+ const errorMessage = error instanceof Error ? error.message : String(error);
24
+ console.log(createUserFriendlyError('Compression', errorMessage, 'Check that the transcript file exists and you have write permissions'));
25
+ throw error; // Re-throw to maintain existing error handling behavior
77
26
  }
78
- // </Block> =======================================
79
27
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Hook command handlers for binary distribution
3
+ * These execute the actual hook logic embedded in the binary
4
+ */
5
+ /**
6
+ * Pre-compact hook handler
7
+ * Runs compression on the Claude Code transcript
8
+ */
9
+ export declare function preCompactHook(): Promise<void>;
10
+ /**
11
+ * Session-start hook handler
12
+ * Loads context for the new session
13
+ */
14
+ export declare function sessionStartHook(): Promise<void>;
15
+ /**
16
+ * Session-end hook handler
17
+ * Compresses session transcript when ending with /clear
18
+ */
19
+ export declare function sessionEndHook(): Promise<void>;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Hook command handlers for binary distribution
3
+ * These execute the actual hook logic embedded in the binary
4
+ */
5
+ import { compress } from './compress.js';
6
+ import { loadContext } from './load-context.js';
7
+ /**
8
+ * Pre-compact hook handler
9
+ * Runs compression on the Claude Code transcript
10
+ */
11
+ export async function preCompactHook() {
12
+ try {
13
+ // Read hook data from stdin (Claude Code sends JSON)
14
+ let inputData = '';
15
+ // Set up stdin to read data
16
+ process.stdin.setEncoding('utf8');
17
+ // Collect all input data
18
+ for await (const chunk of process.stdin) {
19
+ inputData += chunk;
20
+ }
21
+ // Parse the JSON input
22
+ let transcriptPath;
23
+ if (inputData) {
24
+ try {
25
+ const hookData = JSON.parse(inputData);
26
+ transcriptPath = hookData.transcript_path;
27
+ }
28
+ catch (parseError) {
29
+ // If JSON parsing fails, treat the input as a direct path
30
+ transcriptPath = inputData.trim();
31
+ }
32
+ }
33
+ // Fallback to environment variable or command line argument
34
+ if (!transcriptPath) {
35
+ transcriptPath = process.env.TRANSCRIPT_PATH || process.argv[2];
36
+ }
37
+ if (!transcriptPath) {
38
+ console.log('🗜️ Compressing session transcript...');
39
+ console.log('❌ No transcript path provided to pre-compact hook');
40
+ console.log('Hook data received:', inputData || 'none');
41
+ console.log('Environment TRANSCRIPT_PATH:', process.env.TRANSCRIPT_PATH || 'not set');
42
+ console.log('Command line args:', process.argv.slice(2));
43
+ return;
44
+ }
45
+ // Run compression with the transcript path
46
+ await compress(transcriptPath, { dryRun: false });
47
+ }
48
+ catch (error) {
49
+ console.error('Pre-compact hook failed:', error.message);
50
+ process.exit(1);
51
+ }
52
+ }
53
+ /**
54
+ * Session-start hook handler
55
+ * Loads context for the new session
56
+ */
57
+ export async function sessionStartHook() {
58
+ try {
59
+ // Load context with session-start format
60
+ await loadContext({ format: 'session-start', count: '10' });
61
+ }
62
+ catch (error) {
63
+ console.error('Session-start hook failed:', error.message);
64
+ process.exit(1);
65
+ }
66
+ }
67
+ /**
68
+ * Session-end hook handler
69
+ * Compresses session transcript when ending with /clear
70
+ */
71
+ export async function sessionEndHook() {
72
+ try {
73
+ // Read hook data from stdin (Claude Code sends JSON)
74
+ let inputData = '';
75
+ // Set up stdin to read data
76
+ process.stdin.setEncoding('utf8');
77
+ // Collect all input data
78
+ for await (const chunk of process.stdin) {
79
+ inputData += chunk;
80
+ }
81
+ // Parse the JSON input to check the reason for session end
82
+ if (inputData) {
83
+ try {
84
+ const hookData = JSON.parse(inputData);
85
+ // If reason is "clear", compress the session transcript before it's deleted
86
+ if (hookData.reason === 'clear' && hookData.transcript_path) {
87
+ console.log('🗜️ Compressing current session before /clear...');
88
+ await compress(hookData.transcript_path, { dryRun: false });
89
+ }
90
+ }
91
+ catch (parseError) {
92
+ // If JSON parsing fails, log but don't fail the hook
93
+ console.error('Failed to parse hook data:', parseError);
94
+ }
95
+ }
96
+ console.log('Session ended successfully');
97
+ }
98
+ catch (error) {
99
+ console.error('Session-end hook failed:', error.message);
100
+ process.exit(1);
101
+ }
102
+ }