claude-mem 3.0.2 → 3.0.4

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 (56) hide show
  1. package/.mcp.json +11 -0
  2. package/claude-mem +0 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +64 -0
  5. package/dist/commands/compress.d.ts +2 -0
  6. package/dist/commands/compress.js +59 -0
  7. package/dist/commands/install.d.ts +2 -0
  8. package/dist/commands/install.js +372 -0
  9. package/dist/commands/load-context.d.ts +2 -0
  10. package/dist/commands/load-context.js +330 -0
  11. package/dist/commands/logs.d.ts +2 -0
  12. package/dist/commands/logs.js +41 -0
  13. package/dist/commands/migrate.d.ts +9 -0
  14. package/dist/commands/migrate.js +174 -0
  15. package/dist/commands/status.d.ts +1 -0
  16. package/dist/commands/status.js +159 -0
  17. package/dist/commands/uninstall.d.ts +2 -0
  18. package/dist/commands/uninstall.js +105 -0
  19. package/dist/config.d.ts +6 -0
  20. package/dist/config.js +33 -0
  21. package/dist/constants.d.ts +516 -0
  22. package/dist/constants.js +522 -0
  23. package/dist/error-handler.d.ts +17 -0
  24. package/dist/error-handler.js +103 -0
  25. package/dist/mcp-server-cli.d.ts +34 -0
  26. package/dist/mcp-server-cli.js +158 -0
  27. package/dist/mcp-server.d.ts +103 -0
  28. package/dist/mcp-server.js +269 -0
  29. package/dist/types.d.ts +148 -0
  30. package/dist/types.js +78 -0
  31. package/dist/utils/HookDetector.d.ts +64 -0
  32. package/dist/utils/HookDetector.js +213 -0
  33. package/dist/utils/PathResolver.d.ts +16 -0
  34. package/dist/utils/PathResolver.js +55 -0
  35. package/dist/utils/SettingsManager.d.ts +63 -0
  36. package/dist/utils/SettingsManager.js +133 -0
  37. package/dist/utils/TranscriptCompressor.d.ts +111 -0
  38. package/dist/utils/TranscriptCompressor.js +486 -0
  39. package/dist/utils/common.d.ts +29 -0
  40. package/dist/utils/common.js +14 -0
  41. package/dist/utils/error-utils.d.ts +93 -0
  42. package/dist/utils/error-utils.js +238 -0
  43. package/dist/utils/index.d.ts +19 -0
  44. package/dist/utils/index.js +26 -0
  45. package/dist/utils/logger.d.ts +19 -0
  46. package/dist/utils/logger.js +42 -0
  47. package/dist/utils/mcp-client-factory.d.ts +51 -0
  48. package/dist/utils/mcp-client-factory.js +115 -0
  49. package/dist/utils/mcp-client.d.ts +75 -0
  50. package/dist/utils/mcp-client.js +120 -0
  51. package/dist/utils/memory-mcp-client.d.ts +135 -0
  52. package/dist/utils/memory-mcp-client.js +490 -0
  53. package/dist/utils/weaviate-mcp-adapter.d.ts +102 -0
  54. package/dist/utils/weaviate-mcp-adapter.js +587 -0
  55. package/package.json +3 -2
  56. package/src/claude-mem.js +0 -859
@@ -0,0 +1,120 @@
1
+ /**
2
+ * MCP Client for claude-mem
3
+ *
4
+ * This module provides the main interface for MCP operations in claude-mem.
5
+ * It uses embedded Weaviate as the only backend for persistent storage.
6
+ *
7
+ * Key Features:
8
+ * - Embedded Weaviate instance (no external dependencies)
9
+ * - Singleton pattern for efficient resource usage
10
+ * - Persistent storage across sessions
11
+ * - Clean interface matching existing usage patterns
12
+ */
13
+ import { WeaviateMCPAdapter } from './weaviate-mcp-adapter.js';
14
+ /**
15
+ * Singleton instance of the MCP client
16
+ */
17
+ let clientInstance = null;
18
+ let currentSettings = null;
19
+ /**
20
+ * Get or create an MCP client instance
21
+ *
22
+ * This function maintains a singleton pattern using embedded Weaviate.
23
+ * The client persists across calls for efficient resource usage.
24
+ *
25
+ * @param settings - Configuration settings for the client (optional)
26
+ * @returns IMCPClient instance
27
+ */
28
+ export async function getMCPClient(settings = {}) {
29
+ if (!clientInstance) {
30
+ // Create new embedded Weaviate client
31
+ clientInstance = new WeaviateMCPAdapter();
32
+ currentSettings = { ...settings };
33
+ }
34
+ return clientInstance;
35
+ }
36
+ /**
37
+ * Create a new MCP client (bypasses singleton)
38
+ *
39
+ * Use this when you need a fresh client instance without affecting
40
+ * the global singleton. Useful for testing or parallel operations.
41
+ *
42
+ * @param settings - Configuration settings for the client (optional)
43
+ * @returns New IMCPClient instance
44
+ */
45
+ export async function createMCPClient(settings = {}) {
46
+ return new WeaviateMCPAdapter();
47
+ }
48
+ /**
49
+ * Disconnect and reset the global MCP client
50
+ *
51
+ * This function properly cleans up the singleton instance and
52
+ * allows for a fresh client to be created on the next call.
53
+ */
54
+ export async function resetMCPClient() {
55
+ if (clientInstance) {
56
+ try {
57
+ await clientInstance.disconnect();
58
+ }
59
+ catch (error) {
60
+ console.warn('Error disconnecting MCP client during reset:', error);
61
+ }
62
+ clientInstance = null;
63
+ currentSettings = null;
64
+ }
65
+ }
66
+ /**
67
+ * Check if MCP client is connected
68
+ *
69
+ * @returns True if a client instance exists (may not be connected yet)
70
+ */
71
+ export function isMCPClientActive() {
72
+ return clientInstance !== null;
73
+ }
74
+ /**
75
+ * Get current client settings (read-only)
76
+ *
77
+ * @returns Copy of current settings or null if no client exists
78
+ */
79
+ export function getCurrentSettings() {
80
+ return currentSettings ? { ...currentSettings } : null;
81
+ }
82
+ // =============================================================================
83
+ // CONVENIENCE METHODS
84
+ // =============================================================================
85
+ /**
86
+ * Perform an MCP operation with automatic client management
87
+ *
88
+ * This helper function automatically handles client creation, connection,
89
+ * and error handling for common MCP operations.
90
+ *
91
+ * @param operation - Function that performs the MCP operation
92
+ * @param settings - Settings for the MCP client
93
+ * @returns Result of the operation
94
+ */
95
+ export async function withMCPClient(operation, settings = {}) {
96
+ const client = await getMCPClient(settings);
97
+ try {
98
+ await client.connect();
99
+ return await operation(client);
100
+ }
101
+ catch (error) {
102
+ // Don't disconnect on error - the connection might still be valid
103
+ // Let the next operation attempt to use the existing connection
104
+ throw error;
105
+ }
106
+ }
107
+ // =============================================================================
108
+ // EXPORTS FOR BACKWARD COMPATIBILITY
109
+ // =============================================================================
110
+ /**
111
+ * Default export maintains backward compatibility
112
+ */
113
+ export default {
114
+ getMCPClient,
115
+ createMCPClient,
116
+ resetMCPClient,
117
+ isMCPClientActive,
118
+ getCurrentSettings,
119
+ withMCPClient
120
+ };
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Memory MCP Client for claude-mem
3
+ *
4
+ * This client implements the IMCPClient interface using the traditional JSONL file-based
5
+ * storage system. It maintains backward compatibility with the existing claude-mem
6
+ * architecture while providing a clean interface for MCP operations.
7
+ *
8
+ * Key Features:
9
+ * - 100% backward compatibility with existing JSONL index files
10
+ * - Implements full IMCPClient interface
11
+ * - Thread-safe file operations with locking
12
+ * - Efficient search through in-memory indexing
13
+ * - Atomic writes to prevent corruption
14
+ */
15
+ import { IMCPClient, MCPEntity, MCPRelation, MCPSearchResult } from '../types.js';
16
+ /**
17
+ * Memory MCP Client - JSONL file-based implementation
18
+ *
19
+ * This client provides the IMCPClient interface while using the existing
20
+ * JSONL file storage system for backward compatibility.
21
+ */
22
+ export declare class MemoryMCPClient implements IMCPClient {
23
+ private static instance;
24
+ private isConnected;
25
+ private cache;
26
+ private readonly configDir;
27
+ private readonly indexDir;
28
+ private readonly indexPath;
29
+ private readonly lockPath;
30
+ /**
31
+ * Singleton pattern - ensures only one instance manages file operations
32
+ */
33
+ static getInstance(): MemoryMCPClient;
34
+ constructor();
35
+ /**
36
+ * Connect to the memory backend (initialize file system)
37
+ */
38
+ connect(): Promise<void>;
39
+ /**
40
+ * Disconnect from the memory backend (cleanup)
41
+ */
42
+ disconnect(): Promise<void>;
43
+ /**
44
+ * Create entities in the memory backend
45
+ */
46
+ createEntities(entities: MCPEntity[]): Promise<void>;
47
+ /**
48
+ * Create relations in the memory backend
49
+ */
50
+ createRelations(relations: MCPRelation[]): Promise<void>;
51
+ /**
52
+ * Search nodes using text-based matching
53
+ */
54
+ searchNodes(query: string): Promise<MCPSearchResult>;
55
+ /**
56
+ * Open specific nodes by exact name matching
57
+ */
58
+ openNodes(names: string[]): Promise<MCPSearchResult>;
59
+ /**
60
+ * Ensure required directories exist
61
+ */
62
+ private ensureDirectories;
63
+ /**
64
+ * Load cache from JSONL files
65
+ */
66
+ private loadCache;
67
+ /**
68
+ * Ensure cache is loaded and up to date
69
+ */
70
+ private ensureCacheLoaded;
71
+ /**
72
+ * Execute operation with file locking
73
+ */
74
+ private withFileLock;
75
+ /**
76
+ * Append entry to JSONL index file
77
+ */
78
+ private appendToIndex;
79
+ /**
80
+ * Check if entity matches search query
81
+ */
82
+ private matchesEntity;
83
+ /**
84
+ * Check if relation matches search query
85
+ */
86
+ private matchesRelation;
87
+ /**
88
+ * Generate unique ID for index entries
89
+ */
90
+ private generateId;
91
+ /**
92
+ * Generate session ID (simplified)
93
+ */
94
+ private generateSessionId;
95
+ /**
96
+ * Extract project name from entities
97
+ */
98
+ private extractProjectFromEntities;
99
+ /**
100
+ * Extract project name from relations
101
+ */
102
+ private extractProjectFromRelations;
103
+ /**
104
+ * Generate summary from entities
105
+ */
106
+ private generateSummaryFromEntities;
107
+ /**
108
+ * Generate summary from relations
109
+ */
110
+ private generateSummaryFromRelations;
111
+ /**
112
+ * Extract keywords from entities
113
+ */
114
+ private extractKeywords;
115
+ /**
116
+ * Extract keywords from relations
117
+ */
118
+ private extractKeywordsFromRelations;
119
+ /**
120
+ * Get unique nodes from relations
121
+ */
122
+ private getUniqueNodesFromRelations;
123
+ /**
124
+ * Utility method for async delays
125
+ */
126
+ private sleep;
127
+ }
128
+ /**
129
+ * Factory function to create MemoryMCPClient instance
130
+ */
131
+ export declare function createMemoryMCPClient(): IMCPClient;
132
+ /**
133
+ * Default export for convenience
134
+ */
135
+ export default MemoryMCPClient;