claude-mem 3.2.0 → 3.2.1

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 (50) hide show
  1. package/claude-mem +0 -0
  2. package/package.json +1 -2
  3. package/dist/bin/cli.d.ts +0 -2
  4. package/dist/bin/cli.js +0 -129
  5. package/dist/commands/compress.d.ts +0 -2
  6. package/dist/commands/compress.js +0 -27
  7. package/dist/commands/hooks.d.ts +0 -19
  8. package/dist/commands/hooks.js +0 -131
  9. package/dist/commands/install.d.ts +0 -2
  10. package/dist/commands/install.js +0 -649
  11. package/dist/commands/load-context.d.ts +0 -2
  12. package/dist/commands/load-context.js +0 -108
  13. package/dist/commands/logs.d.ts +0 -2
  14. package/dist/commands/logs.js +0 -76
  15. package/dist/commands/migrate-to-jsonl.d.ts +0 -5
  16. package/dist/commands/migrate-to-jsonl.js +0 -99
  17. package/dist/commands/status.d.ts +0 -1
  18. package/dist/commands/status.js +0 -136
  19. package/dist/commands/uninstall.d.ts +0 -2
  20. package/dist/commands/uninstall.js +0 -107
  21. package/dist/constants.d.ts +0 -271
  22. package/dist/constants.js +0 -199
  23. package/dist/core/compression/TranscriptCompressor.d.ts +0 -83
  24. package/dist/core/compression/TranscriptCompressor.js +0 -602
  25. package/dist/core/orchestration/PromptOrchestrator.d.ts +0 -165
  26. package/dist/core/orchestration/PromptOrchestrator.js +0 -182
  27. package/dist/lib/time-utils.d.ts +0 -5
  28. package/dist/lib/time-utils.js +0 -70
  29. package/dist/prompts/constants.d.ts +0 -126
  30. package/dist/prompts/constants.js +0 -161
  31. package/dist/prompts/index.d.ts +0 -10
  32. package/dist/prompts/index.js +0 -11
  33. package/dist/prompts/templates/analysis/AnalysisTemplates.d.ts +0 -13
  34. package/dist/prompts/templates/analysis/AnalysisTemplates.js +0 -94
  35. package/dist/prompts/templates/context/ContextTemplates.d.ts +0 -119
  36. package/dist/prompts/templates/context/ContextTemplates.js +0 -399
  37. package/dist/prompts/templates/hooks/HookTemplates.d.ts +0 -175
  38. package/dist/prompts/templates/hooks/HookTemplates.js +0 -394
  39. package/dist/prompts/templates/hooks/HookTemplates.test.d.ts +0 -7
  40. package/dist/prompts/templates/hooks/HookTemplates.test.js +0 -127
  41. package/dist/shared/config.d.ts +0 -4
  42. package/dist/shared/config.js +0 -41
  43. package/dist/shared/error-handler.d.ts +0 -22
  44. package/dist/shared/error-handler.js +0 -142
  45. package/dist/shared/logger.d.ts +0 -19
  46. package/dist/shared/logger.js +0 -51
  47. package/dist/shared/paths.d.ts +0 -28
  48. package/dist/shared/paths.js +0 -100
  49. package/dist/shared/types.d.ts +0 -141
  50. package/dist/shared/types.js +0 -78
@@ -1,394 +0,0 @@
1
- /**
2
- * Hook Templates for System Integration
3
- *
4
- * This module provides standardized templates for hook responses that integrate
5
- * with Claude Code's hook system. These templates ensure consistent formatting
6
- * and proper JSON structure for different hook events.
7
- *
8
- * Based on Claude Code Hook Documentation v2025
9
- */
10
- // =============================================================================
11
- // PRE-COMPACT HOOK TEMPLATES
12
- // =============================================================================
13
- /**
14
- * Creates a successful pre-compact response that allows compression to proceed
15
- * PreCompact hooks do NOT support hookSpecificOutput according to documentation
16
- */
17
- export function createPreCompactSuccessResponse() {
18
- return {
19
- continue: true,
20
- suppressOutput: true
21
- };
22
- }
23
- /**
24
- * Creates a blocked pre-compact response that prevents compression
25
- */
26
- export function createPreCompactBlockedResponse(reason) {
27
- return {
28
- continue: false,
29
- stopReason: reason,
30
- suppressOutput: true
31
- };
32
- }
33
- /**
34
- * Creates a pre-compact response with approval decision
35
- */
36
- export function createPreCompactApprovalResponse(decision, reason) {
37
- return {
38
- decision,
39
- reason,
40
- continue: decision === 'approve',
41
- suppressOutput: true
42
- };
43
- }
44
- // =============================================================================
45
- // SESSION START HOOK TEMPLATES
46
- // =============================================================================
47
- /**
48
- * Creates a successful session start response with loaded context
49
- * SessionStart hooks DO support hookSpecificOutput
50
- */
51
- export function createSessionStartSuccessResponse(additionalContext) {
52
- return {
53
- continue: true,
54
- suppressOutput: true,
55
- hookSpecificOutput: {
56
- hookEventName: 'SessionStart',
57
- additionalContext
58
- }
59
- };
60
- }
61
- /**
62
- * Creates a session start response when no context is available
63
- */
64
- export function createSessionStartEmptyResponse() {
65
- return {
66
- continue: true,
67
- suppressOutput: true,
68
- hookSpecificOutput: {
69
- hookEventName: 'SessionStart',
70
- additionalContext: 'Starting fresh session - no previous context available'
71
- }
72
- };
73
- }
74
- /**
75
- * Creates a session start response with error information
76
- */
77
- export function createSessionStartErrorResponse(error) {
78
- return {
79
- continue: true, // Continue even if context loading fails
80
- suppressOutput: true,
81
- hookSpecificOutput: {
82
- hookEventName: 'SessionStart',
83
- additionalContext: `Context loading encountered an issue: ${error}. Starting without previous context.`
84
- }
85
- };
86
- }
87
- /**
88
- * Creates a rich session start response with memory summary
89
- */
90
- export function createSessionStartMemoryResponse(memoryData) {
91
- const { projectName, memoryCount, lastSessionTime, recentComponents = [], recentDecisions = [] } = memoryData;
92
- const timeInfo = lastSessionTime ? ` (last worked: ${lastSessionTime})` : '';
93
- const contextParts = [];
94
- contextParts.push(`🧠 Loaded ${memoryCount} memories from previous sessions for ${projectName}${timeInfo}`);
95
- if (recentComponents.length > 0) {
96
- contextParts.push(`\n🎯 Recent components: ${recentComponents.slice(0, 3).join(', ')}`);
97
- }
98
- if (recentDecisions.length > 0) {
99
- contextParts.push(`\n🔄 Recent decisions: ${recentDecisions.slice(0, 2).join(', ')}`);
100
- }
101
- contextParts.push('\n💡 Use chroma_query_documents(["keywords"]) to find related work or chroma_get_documents(["document_id"]) to load specific content');
102
- return {
103
- continue: true,
104
- suppressOutput: true,
105
- hookSpecificOutput: {
106
- hookEventName: 'SessionStart',
107
- additionalContext: contextParts.join('')
108
- }
109
- };
110
- }
111
- // =============================================================================
112
- // PRE-TOOL USE HOOK TEMPLATES
113
- // =============================================================================
114
- /**
115
- * Creates a pre-tool use response that allows the tool to execute
116
- */
117
- export function createPreToolUseAllowResponse(reason) {
118
- return {
119
- continue: true,
120
- suppressOutput: true,
121
- permissionDecision: 'allow',
122
- permissionDecisionReason: reason
123
- };
124
- }
125
- /**
126
- * Creates a pre-tool use response that blocks the tool execution
127
- */
128
- export function createPreToolUseDenyResponse(reason) {
129
- return {
130
- continue: false,
131
- stopReason: reason,
132
- suppressOutput: true,
133
- permissionDecision: 'deny',
134
- permissionDecisionReason: reason
135
- };
136
- }
137
- /**
138
- * Creates a pre-tool use response that asks for user confirmation
139
- */
140
- export function createPreToolUseAskResponse(reason) {
141
- return {
142
- continue: true,
143
- suppressOutput: false, // Show output so user can see the question
144
- permissionDecision: 'ask',
145
- permissionDecisionReason: reason
146
- };
147
- }
148
- // =============================================================================
149
- // GENERIC HOOK RESPONSE TEMPLATES
150
- // =============================================================================
151
- /**
152
- * Creates a basic success response for any hook type
153
- */
154
- export function createHookSuccessResponse(suppressOutput = true) {
155
- return {
156
- continue: true,
157
- suppressOutput
158
- };
159
- }
160
- /**
161
- * Creates a basic error response for any hook type
162
- */
163
- export function createHookErrorResponse(reason, suppressOutput = true) {
164
- return {
165
- continue: false,
166
- stopReason: reason,
167
- suppressOutput
168
- };
169
- }
170
- /**
171
- * Creates a response with system message (warning/info for user)
172
- */
173
- export function createHookSystemMessageResponse(message, continueProcessing = true) {
174
- return {
175
- continue: continueProcessing,
176
- suppressOutput: true,
177
- systemMessage: message
178
- };
179
- }
180
- // =============================================================================
181
- // OPERATION STATUS TEMPLATES
182
- // =============================================================================
183
- /**
184
- * Templates for different types of operation status messages
185
- */
186
- export const OPERATION_STATUS_TEMPLATES = {
187
- // Compression operations
188
- COMPRESSION_STARTED: 'Starting memory compression...',
189
- COMPRESSION_ANALYZING: 'Analyzing transcript content...',
190
- COMPRESSION_EXTRACTING: 'Extracting memories and connections...',
191
- COMPRESSION_SAVING: 'Saving compressed memories...',
192
- COMPRESSION_COMPLETE: (count, duration) => `Memory compression complete. Extracted ${count} memories${duration ? ` in ${Math.round(duration / 1000)}s` : ''}`,
193
- // Context loading operations
194
- CONTEXT_LOADING: 'Loading previous session context...',
195
- CONTEXT_SEARCHING: 'Searching for relevant memories...',
196
- CONTEXT_FORMATTING: 'Organizing context for display...',
197
- CONTEXT_LOADED: (count) => `Context loaded successfully. Found ${count} relevant memories`,
198
- CONTEXT_EMPTY: 'No previous context found. Starting fresh session',
199
- // Tool operations
200
- TOOL_CHECKING: (toolName) => `Checking permissions for ${toolName}...`,
201
- TOOL_ALLOWED: (toolName) => `✅ ${toolName} execution approved`,
202
- TOOL_BLOCKED: (toolName, reason) => `❌ ${toolName} blocked: ${reason}`,
203
- // General operations
204
- OPERATION_STARTING: (operation) => `Starting ${operation}...`,
205
- OPERATION_PROGRESS: (operation, current, total) => `${operation}: ${current}/${total} (${Math.round((current / total) * 100)}%)`,
206
- OPERATION_COMPLETE: (operation) => `✅ ${operation} completed successfully`,
207
- OPERATION_FAILED: (operation, error) => `❌ ${operation} failed: ${error}`
208
- };
209
- /**
210
- * Creates a progress message for long-running operations
211
- */
212
- export function createProgressMessage(operation, progress) {
213
- const { current, total, currentStep, estimatedRemaining } = progress;
214
- const percentage = Math.round((current / total) * 100);
215
- let message = `${operation}: ${current}/${total} (${percentage}%)`;
216
- if (currentStep) {
217
- message += ` - ${currentStep}`;
218
- }
219
- if (estimatedRemaining && estimatedRemaining > 1000) {
220
- const seconds = Math.round(estimatedRemaining / 1000);
221
- message += ` (${seconds}s remaining)`;
222
- }
223
- return message;
224
- }
225
- // =============================================================================
226
- // ERROR RESPONSE TEMPLATES
227
- // =============================================================================
228
- /**
229
- * Standard error messages for different failure scenarios
230
- */
231
- export const ERROR_RESPONSE_TEMPLATES = {
232
- // File system errors
233
- FILE_NOT_FOUND: (path) => `File not found: ${path}`,
234
- FILE_READ_ERROR: (path, error) => `Failed to read ${path}: ${error}`,
235
- FILE_WRITE_ERROR: (path, error) => `Failed to write ${path}: ${error}`,
236
- // Network/connection errors
237
- CONNECTION_FAILED: (service) => `Failed to connect to ${service}`,
238
- CONNECTION_TIMEOUT: (service) => `Connection to ${service} timed out`,
239
- // Validation errors
240
- INVALID_PAYLOAD: (field) => `Invalid or missing field: ${field}`,
241
- INVALID_FORMAT: (expected, received) => `Expected ${expected}, received ${received}`,
242
- // Operation errors
243
- OPERATION_TIMEOUT: (operation, timeout) => `${operation} timed out after ${timeout}ms`,
244
- OPERATION_CANCELLED: (operation) => `${operation} was cancelled`,
245
- INSUFFICIENT_PERMISSIONS: (operation) => `Insufficient permissions for ${operation}`,
246
- // Memory system errors
247
- MEMORY_SYSTEM_UNAVAILABLE: 'Memory system is not available',
248
- MEMORY_CORRUPTION: 'Memory index appears to be corrupted',
249
- MEMORY_SEARCH_FAILED: (query) => `Memory search failed for query: "${query}"`,
250
- // Compression errors
251
- COMPRESSION_FAILED: (stage) => `Compression failed during ${stage}`,
252
- INVALID_TRANSCRIPT: 'Transcript file is invalid or corrupted',
253
- // General errors
254
- UNKNOWN_ERROR: (context) => `An unexpected error occurred during ${context}`,
255
- SYSTEM_ERROR: (error) => `System error: ${error}`
256
- };
257
- /**
258
- * Creates a standardized error response with troubleshooting guidance
259
- */
260
- export function createDetailedErrorResponse(operation, error, troubleshootingSteps = []) {
261
- const baseMessage = `${operation} failed: ${error}`;
262
- const fullMessage = troubleshootingSteps.length > 0
263
- ? `${baseMessage}\n\nTroubleshooting steps:\n${troubleshootingSteps.map(step => `• ${step}`).join('\n')}`
264
- : baseMessage;
265
- return {
266
- continue: false,
267
- stopReason: fullMessage,
268
- suppressOutput: false // Show error details to user
269
- };
270
- }
271
- // =============================================================================
272
- // HOOK RESPONSE VALIDATION
273
- // =============================================================================
274
- /**
275
- * Validates that a hook response conforms to Claude Code expectations
276
- */
277
- export function validateHookResponse(response, hookType) {
278
- const errors = [];
279
- // Check required fields
280
- if (typeof response !== 'object' || response === null) {
281
- errors.push('Response must be a valid JSON object');
282
- return { isValid: false, errors };
283
- }
284
- // Validate continue field
285
- if (response.continue !== undefined && typeof response.continue !== 'boolean') {
286
- errors.push('continue field must be a boolean');
287
- }
288
- // Validate suppressOutput field
289
- if (response.suppressOutput !== undefined && typeof response.suppressOutput !== 'boolean') {
290
- errors.push('suppressOutput field must be a boolean');
291
- }
292
- // Validate stopReason field
293
- if (response.stopReason !== undefined && typeof response.stopReason !== 'string') {
294
- errors.push('stopReason field must be a string');
295
- }
296
- // Hook-specific validations
297
- if (hookType === 'PreCompact') {
298
- // PreCompact should not have hookSpecificOutput
299
- if (response.hookSpecificOutput !== undefined) {
300
- errors.push('PreCompact hooks do not support hookSpecificOutput');
301
- }
302
- // Validate decision field if present
303
- if (response.decision !== undefined && !['approve', 'block'].includes(response.decision)) {
304
- errors.push('decision field must be "approve" or "block"');
305
- }
306
- }
307
- if (hookType === 'SessionStart') {
308
- // Validate hookSpecificOutput structure
309
- if (response.hookSpecificOutput) {
310
- const hso = response.hookSpecificOutput;
311
- if (hso.hookEventName !== 'SessionStart') {
312
- errors.push('hookSpecificOutput.hookEventName must be "SessionStart"');
313
- }
314
- if (hso.additionalContext !== undefined && typeof hso.additionalContext !== 'string') {
315
- errors.push('hookSpecificOutput.additionalContext must be a string');
316
- }
317
- }
318
- }
319
- if (hookType === 'PreToolUse') {
320
- // Validate permissionDecision field
321
- if (response.permissionDecision !== undefined) {
322
- if (!['allow', 'deny', 'ask'].includes(response.permissionDecision)) {
323
- errors.push('permissionDecision must be "allow", "deny", or "ask"');
324
- }
325
- }
326
- }
327
- return {
328
- isValid: errors.length === 0,
329
- errors
330
- };
331
- }
332
- // =============================================================================
333
- // UTILITY FUNCTIONS
334
- // =============================================================================
335
- /**
336
- * Creates a hook response based on context and automatically handles hook-specific formatting
337
- */
338
- export function createContextualHookResponse(context) {
339
- const { hookEventName, success, message, additionalData, duration, itemCount } = context;
340
- // Base response
341
- const response = {
342
- continue: success,
343
- suppressOutput: true
344
- };
345
- // Add failure reason if not successful
346
- if (!success && message) {
347
- response.stopReason = message;
348
- response.suppressOutput = false; // Show error to user
349
- }
350
- // Handle hook-specific output
351
- if (success && hookEventName === 'SessionStart' && message) {
352
- return {
353
- ...response,
354
- hookSpecificOutput: {
355
- hookEventName: 'SessionStart',
356
- additionalContext: message
357
- }
358
- };
359
- }
360
- // Handle PreCompact approval
361
- if (hookEventName === 'PreCompact') {
362
- return {
363
- ...response,
364
- decision: success ? 'approve' : 'block',
365
- reason: message
366
- };
367
- }
368
- return response;
369
- }
370
- /**
371
- * Formats duration in milliseconds to human-readable format
372
- */
373
- export function formatDuration(milliseconds) {
374
- if (milliseconds < 1000) {
375
- return `${milliseconds}ms`;
376
- }
377
- const seconds = Math.round(milliseconds / 1000);
378
- if (seconds < 60) {
379
- return `${seconds}s`;
380
- }
381
- const minutes = Math.floor(seconds / 60);
382
- const remainingSeconds = seconds % 60;
383
- return remainingSeconds > 0 ? `${minutes}m ${remainingSeconds}s` : `${minutes}m`;
384
- }
385
- /**
386
- * Creates a summary line for operation completion
387
- */
388
- export function createOperationSummary(operation, success, duration, itemCount, details) {
389
- const status = success ? '✅' : '❌';
390
- const durationText = duration ? ` in ${formatDuration(duration)}` : '';
391
- const itemText = itemCount ? ` (${itemCount} items)` : '';
392
- const detailText = details ? ` - ${details}` : '';
393
- return `${status} ${operation}${itemText}${durationText}${detailText}`;
394
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Hook Templates Test
3
- *
4
- * Basic validation tests for hook response templates to ensure they
5
- * generate valid responses that conform to Claude Code's hook system.
6
- */
7
- export {};
@@ -1,127 +0,0 @@
1
- /**
2
- * Hook Templates Test
3
- *
4
- * Basic validation tests for hook response templates to ensure they
5
- * generate valid responses that conform to Claude Code's hook system.
6
- */
7
- import { createPreCompactSuccessResponse, createPreCompactBlockedResponse, createPreCompactApprovalResponse, createSessionStartSuccessResponse, createSessionStartEmptyResponse, createSessionStartErrorResponse, createSessionStartMemoryResponse, createPreToolUseAllowResponse, createPreToolUseDenyResponse, createPreToolUseAskResponse, createHookSuccessResponse, createHookErrorResponse, validateHookResponse, createContextualHookResponse, formatDuration, createOperationSummary, OPERATION_STATUS_TEMPLATES, ERROR_RESPONSE_TEMPLATES } from './HookTemplates.js';
8
- // =============================================================================
9
- // PRE-COMPACT HOOK TESTS
10
- // =============================================================================
11
- console.log('Testing Pre-Compact Hook Templates...');
12
- // Test successful pre-compact response
13
- const preCompactSuccess = createPreCompactSuccessResponse();
14
- console.log('✓ Pre-compact success:', JSON.stringify(preCompactSuccess, null, 2));
15
- // Test blocked pre-compact response
16
- const preCompactBlocked = createPreCompactBlockedResponse('User requested to skip compression');
17
- console.log('✓ Pre-compact blocked:', JSON.stringify(preCompactBlocked, null, 2));
18
- // Test approval response
19
- const preCompactApproval = createPreCompactApprovalResponse('approve', 'Compression approved by policy');
20
- console.log('✓ Pre-compact approval:', JSON.stringify(preCompactApproval, null, 2));
21
- // =============================================================================
22
- // SESSION START HOOK TESTS
23
- // =============================================================================
24
- console.log('\nTesting Session Start Hook Templates...');
25
- // Test successful session start with context
26
- const sessionStartSuccess = createSessionStartSuccessResponse('Loaded 5 memories from previous sessions');
27
- console.log('✓ Session start success:', JSON.stringify(sessionStartSuccess, null, 2));
28
- // Test empty session start
29
- const sessionStartEmpty = createSessionStartEmptyResponse();
30
- console.log('✓ Session start empty:', JSON.stringify(sessionStartEmpty, null, 2));
31
- // Test error session start
32
- const sessionStartError = createSessionStartErrorResponse('Memory index corrupted');
33
- console.log('✓ Session start error:', JSON.stringify(sessionStartError, null, 2));
34
- // Test rich memory response
35
- const sessionStartMemory = createSessionStartMemoryResponse({
36
- projectName: 'claude-mem',
37
- memoryCount: 12,
38
- lastSessionTime: '2 hours ago',
39
- recentComponents: ['PromptOrchestrator', 'HookTemplates', 'MCPClient'],
40
- recentDecisions: ['Use TypeScript for type safety', 'Implement embedded Weaviate']
41
- });
42
- console.log('✓ Session start memory:', JSON.stringify(sessionStartMemory, null, 2));
43
- // =============================================================================
44
- // PRE-TOOL USE HOOK TESTS
45
- // =============================================================================
46
- console.log('\nTesting Pre-Tool Use Hook Templates...');
47
- // Test allow response
48
- const preToolAllow = createPreToolUseAllowResponse('Tool execution approved by security policy');
49
- console.log('✓ Pre-tool allow:', JSON.stringify(preToolAllow, null, 2));
50
- // Test deny response
51
- const preToolDeny = createPreToolUseDenyResponse('Bash commands disabled in restricted mode');
52
- console.log('✓ Pre-tool deny:', JSON.stringify(preToolDeny, null, 2));
53
- // Test ask response
54
- const preToolAsk = createPreToolUseAskResponse('File operation requires user confirmation');
55
- console.log('✓ Pre-tool ask:', JSON.stringify(preToolAsk, null, 2));
56
- // =============================================================================
57
- // GENERIC HOOK TESTS
58
- // =============================================================================
59
- console.log('\nTesting Generic Hook Templates...');
60
- // Test basic success
61
- const genericSuccess = createHookSuccessResponse(false);
62
- console.log('✓ Generic success:', JSON.stringify(genericSuccess, null, 2));
63
- // Test basic error
64
- const genericError = createHookErrorResponse('Operation failed due to network timeout', true);
65
- console.log('✓ Generic error:', JSON.stringify(genericError, null, 2));
66
- // =============================================================================
67
- // VALIDATION TESTS
68
- // =============================================================================
69
- console.log('\nTesting Hook Response Validation...');
70
- // Test valid PreCompact response
71
- const preCompactValidation = validateHookResponse(preCompactSuccess, 'PreCompact');
72
- console.log('✓ PreCompact validation:', preCompactValidation);
73
- // Test invalid PreCompact response (with hookSpecificOutput)
74
- const invalidPreCompact = {
75
- continue: true,
76
- hookSpecificOutput: { hookEventName: 'PreCompact' }
77
- };
78
- const preCompactInvalidValidation = validateHookResponse(invalidPreCompact, 'PreCompact');
79
- console.log('✓ PreCompact invalid validation:', preCompactInvalidValidation);
80
- // Test valid SessionStart response
81
- const sessionStartValidation = validateHookResponse(sessionStartSuccess, 'SessionStart');
82
- console.log('✓ SessionStart validation:', sessionStartValidation);
83
- // =============================================================================
84
- // CONTEXTUAL HOOK RESPONSE TESTS
85
- // =============================================================================
86
- console.log('\nTesting Contextual Hook Responses...');
87
- // Test successful session start context
88
- const contextualSessionStart = createContextualHookResponse({
89
- hookEventName: 'SessionStart',
90
- sessionId: 'test-123',
91
- success: true,
92
- message: 'Successfully loaded 8 memories from previous claude-mem sessions'
93
- });
94
- console.log('✓ Contextual SessionStart:', JSON.stringify(contextualSessionStart, null, 2));
95
- // Test failed PreCompact context
96
- const contextualPreCompactFail = createContextualHookResponse({
97
- hookEventName: 'PreCompact',
98
- sessionId: 'test-123',
99
- success: false,
100
- message: 'Compression blocked: insufficient disk space'
101
- });
102
- console.log('✓ Contextual PreCompact fail:', JSON.stringify(contextualPreCompactFail, null, 2));
103
- // =============================================================================
104
- // UTILITY FUNCTION TESTS
105
- // =============================================================================
106
- console.log('\nTesting Utility Functions...');
107
- // Test duration formatting
108
- console.log('✓ Duration 500ms:', formatDuration(500));
109
- console.log('✓ Duration 5s:', formatDuration(5000));
110
- console.log('✓ Duration 90s:', formatDuration(90000));
111
- console.log('✓ Duration 2m30s:', formatDuration(150000));
112
- // Test operation summary
113
- console.log('✓ Operation summary success:', createOperationSummary('Memory compression', true, 5000, 15, 'entities extracted'));
114
- console.log('✓ Operation summary failure:', createOperationSummary('Context loading', false, 2000, 0, 'connection timeout'));
115
- // =============================================================================
116
- // TEMPLATE CONSTANT TESTS
117
- // =============================================================================
118
- console.log('\nTesting Template Constants...');
119
- // Test operation status templates
120
- console.log('✓ Compression complete:', OPERATION_STATUS_TEMPLATES.COMPRESSION_COMPLETE(25, 5000));
121
- console.log('✓ Context loaded:', OPERATION_STATUS_TEMPLATES.CONTEXT_LOADED(8));
122
- console.log('✓ Tool allowed:', OPERATION_STATUS_TEMPLATES.TOOL_ALLOWED('Bash'));
123
- // Test error response templates
124
- console.log('✓ File not found:', ERROR_RESPONSE_TEMPLATES.FILE_NOT_FOUND('/path/to/transcript.txt'));
125
- console.log('✓ Connection failed:', ERROR_RESPONSE_TEMPLATES.CONNECTION_FAILED('MCP memory server'));
126
- console.log('✓ Operation timeout:', ERROR_RESPONSE_TEMPLATES.OPERATION_TIMEOUT('compression', 30000));
127
- console.log('\n✅ All hook template tests completed successfully!');
@@ -1,4 +0,0 @@
1
- export declare const PACKAGE_NAME: string;
2
- export declare const PACKAGE_VERSION: string;
3
- export declare const PACKAGE_DESCRIPTION: string;
4
- export declare const CLI_NAME: string;
@@ -1,41 +0,0 @@
1
- import { readFileSync, existsSync } from 'fs';
2
- import { join, dirname } from 'path';
3
- import { fileURLToPath } from 'url';
4
- // <Block> 5.1 ====================================
5
- // Default values for compiled binaries
6
- const DEFAULT_PACKAGE_NAME = 'claude-mem';
7
- const DEFAULT_PACKAGE_VERSION = '3.1.5';
8
- const DEFAULT_PACKAGE_DESCRIPTION = 'Memory compression system for Claude Code - persist context across sessions';
9
- let packageName = DEFAULT_PACKAGE_NAME;
10
- let packageVersion = DEFAULT_PACKAGE_VERSION;
11
- let packageDescription = DEFAULT_PACKAGE_DESCRIPTION;
12
- // </Block> =======================================
13
- // Try to read package.json if it exists (for development)
14
- // <Block> 5.2 ====================================
15
- try {
16
- const __filename = fileURLToPath(import.meta.url);
17
- const __dirname = dirname(__filename);
18
- const packageJsonPath = join(__dirname, '..', 'package.json');
19
- // <Block> 5.2a ====================================
20
- if (existsSync(packageJsonPath)) {
21
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
22
- // <Block> 5.2b ====================================
23
- packageName = packageJson.name || DEFAULT_PACKAGE_NAME;
24
- packageVersion = packageJson.version || DEFAULT_PACKAGE_VERSION;
25
- packageDescription = packageJson.description || DEFAULT_PACKAGE_DESCRIPTION;
26
- // </Block> =======================================
27
- }
28
- // </Block> =======================================
29
- }
30
- catch {
31
- // Use defaults if package.json can't be read (compiled binary)
32
- }
33
- // </Block> =======================================
34
- // <Block> 5.3 ====================================
35
- // Export package configuration
36
- export const PACKAGE_NAME = packageName;
37
- export const PACKAGE_VERSION = packageVersion;
38
- export const PACKAGE_DESCRIPTION = packageDescription;
39
- // Export commonly used names
40
- export const CLI_NAME = PACKAGE_NAME; // The CLI command name
41
- // </Block> =======================================
@@ -1,22 +0,0 @@
1
- export declare class ErrorHandler {
2
- private logger;
3
- private logDir;
4
- constructor(enableDebug?: boolean);
5
- private ensureLogDirectory;
6
- handleHookError(error: Error, hookType: string, payload?: unknown): never;
7
- handleCompressionError(error: Error, transcriptPath: string, stage: string): never;
8
- handleValidationError(message: string, context?: Record<string, unknown>): never;
9
- logSuccess(operation: string, details?: Record<string, unknown>): void;
10
- logWarning(message: string, details?: Record<string, unknown>): void;
11
- logDebug(message: string, details?: Record<string, unknown>): void;
12
- }
13
- export declare function parseStdinJson<T = unknown>(input: string): T;
14
- export declare function safeExecute<T>(operation: () => Promise<T>, errorHandler: ErrorHandler, context: string): Promise<T>;
15
- export declare function validateFileExists(filePath: string, errorHandler: ErrorHandler): void;
16
- /**
17
- * Creates a standardized hook response using HookTemplates
18
- * @deprecated Use HookTemplates.createHookSuccessResponse or createHookErrorResponse instead
19
- * This function is maintained for backward compatibility but should be replaced with HookTemplates.
20
- */
21
- export declare function createHookResponse(success: boolean, data?: Record<string, unknown>): string;
22
- export declare const globalErrorHandler: ErrorHandler;