claude-conversation-memory-mcp 0.5.0 → 1.0.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/README.md +16 -0
- package/dist/ConversationMemory.d.ts +151 -10
- package/dist/ConversationMemory.d.ts.map +1 -1
- package/dist/ConversationMemory.js +127 -10
- package/dist/ConversationMemory.js.map +1 -1
- package/dist/cache/QueryCache.d.ts +215 -0
- package/dist/cache/QueryCache.d.ts.map +1 -0
- package/dist/cache/QueryCache.js +294 -0
- package/dist/cache/QueryCache.js.map +1 -0
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +3 -0
- package/dist/mcp-server.js.map +1 -1
- package/dist/parsers/ConversationParser.d.ts +62 -3
- package/dist/parsers/ConversationParser.d.ts.map +1 -1
- package/dist/parsers/ConversationParser.js +50 -3
- package/dist/parsers/ConversationParser.js.map +1 -1
- package/dist/parsers/DecisionExtractor.d.ts +61 -3
- package/dist/parsers/DecisionExtractor.d.ts.map +1 -1
- package/dist/parsers/DecisionExtractor.js +47 -3
- package/dist/parsers/DecisionExtractor.js.map +1 -1
- package/dist/parsers/GitIntegrator.d.ts +88 -3
- package/dist/parsers/GitIntegrator.d.ts.map +1 -1
- package/dist/parsers/GitIntegrator.js +68 -3
- package/dist/parsers/GitIntegrator.js.map +1 -1
- package/dist/parsers/MistakeExtractor.d.ts +62 -3
- package/dist/parsers/MistakeExtractor.d.ts.map +1 -1
- package/dist/parsers/MistakeExtractor.js +50 -3
- package/dist/parsers/MistakeExtractor.js.map +1 -1
- package/dist/parsers/RequirementsExtractor.d.ts +95 -4
- package/dist/parsers/RequirementsExtractor.d.ts.map +1 -1
- package/dist/parsers/RequirementsExtractor.js +73 -4
- package/dist/parsers/RequirementsExtractor.js.map +1 -1
- package/dist/storage/ConversationStorage.d.ts +271 -2
- package/dist/storage/ConversationStorage.d.ts.map +1 -1
- package/dist/storage/ConversationStorage.js +356 -7
- package/dist/storage/ConversationStorage.js.map +1 -1
- package/dist/tools/ToolDefinitions.d.ts +39 -0
- package/dist/tools/ToolDefinitions.d.ts.map +1 -1
- package/dist/tools/ToolDefinitions.js +37 -0
- package/dist/tools/ToolDefinitions.js.map +1 -1
- package/dist/tools/ToolHandlers.d.ts +528 -14
- package/dist/tools/ToolHandlers.d.ts.map +1 -1
- package/dist/tools/ToolHandlers.js +691 -14
- package/dist/tools/ToolHandlers.js.map +1 -1
- package/dist/types/ToolTypes.d.ts +54 -0
- package/dist/types/ToolTypes.d.ts.map +1 -1
- package/dist/utils/Logger.d.ts +67 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +119 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/constants.d.ts +75 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +105 -0
- package/dist/utils/constants.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QueryCache - LRU cache for database query results
|
|
3
|
+
*
|
|
4
|
+
* Provides an in-memory caching layer with:
|
|
5
|
+
* - LRU (Least Recently Used) eviction policy
|
|
6
|
+
* - TTL (Time To Live) for automatic expiration
|
|
7
|
+
* - Cache statistics (hits, misses, evictions, hit rate)
|
|
8
|
+
* - Smart invalidation support
|
|
9
|
+
*
|
|
10
|
+
* Use this to cache expensive database queries like conversation searches,
|
|
11
|
+
* file timelines, and decision lookups.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const cache = new QueryCache({ maxSize: 100, ttlMs: 60000 });
|
|
16
|
+
*
|
|
17
|
+
* // Store query result
|
|
18
|
+
* cache.set('conversations:all', conversations);
|
|
19
|
+
*
|
|
20
|
+
* // Retrieve from cache
|
|
21
|
+
* const cached = cache.get('conversations:all');
|
|
22
|
+
* if (cached) {
|
|
23
|
+
* return cached; // Cache hit
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // Cache miss - query database
|
|
27
|
+
* const result = await queryDatabase();
|
|
28
|
+
* cache.set('conversations:all', result);
|
|
29
|
+
* return result;
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options for QueryCache
|
|
34
|
+
*/
|
|
35
|
+
export interface QueryCacheConfig {
|
|
36
|
+
/** Maximum number of entries to store */
|
|
37
|
+
maxSize: number;
|
|
38
|
+
/** Time to live in milliseconds before entries expire */
|
|
39
|
+
ttlMs: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Cache statistics for monitoring
|
|
43
|
+
*/
|
|
44
|
+
export interface CacheStats {
|
|
45
|
+
/** Number of cache hits */
|
|
46
|
+
hits: number;
|
|
47
|
+
/** Number of cache misses */
|
|
48
|
+
misses: number;
|
|
49
|
+
/** Number of entries evicted */
|
|
50
|
+
evictions: number;
|
|
51
|
+
/** Cache hit rate (0-1) */
|
|
52
|
+
hitRate: number;
|
|
53
|
+
/** Current cache size */
|
|
54
|
+
size: number;
|
|
55
|
+
/** Maximum cache size */
|
|
56
|
+
maxSize: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* LRU cache with TTL support for database query results.
|
|
60
|
+
*
|
|
61
|
+
* Uses a Map for O(1) access and maintains LRU order by moving
|
|
62
|
+
* accessed entries to the end of the Map.
|
|
63
|
+
*/
|
|
64
|
+
export declare class QueryCache {
|
|
65
|
+
private cache;
|
|
66
|
+
private readonly config;
|
|
67
|
+
private stats;
|
|
68
|
+
/**
|
|
69
|
+
* Create a new QueryCache.
|
|
70
|
+
*
|
|
71
|
+
* @param config - Cache configuration
|
|
72
|
+
* @throws {Error} If configuration is invalid
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Create cache with 100 entries, 1 minute TTL
|
|
77
|
+
* const cache = new QueryCache({ maxSize: 100, ttlMs: 60000 });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
constructor(config?: Partial<QueryCacheConfig>);
|
|
81
|
+
/**
|
|
82
|
+
* Store a value in the cache.
|
|
83
|
+
*
|
|
84
|
+
* If the key already exists, updates the value and resets TTL.
|
|
85
|
+
* If cache is full, evicts the least recently used entry.
|
|
86
|
+
*
|
|
87
|
+
* @param key - Cache key
|
|
88
|
+
* @param value - Value to cache
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* cache.set('user:123', { id: 123, name: 'Alice' });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
set<T>(key: string, value: T): void;
|
|
96
|
+
/**
|
|
97
|
+
* Retrieve a value from the cache.
|
|
98
|
+
*
|
|
99
|
+
* Returns undefined if key doesn't exist or entry has expired.
|
|
100
|
+
* Updates access order (moves entry to end as most recently used).
|
|
101
|
+
*
|
|
102
|
+
* @param key - Cache key
|
|
103
|
+
* @returns Cached value or undefined
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const user = cache.get<User>('user:123');
|
|
108
|
+
* if (user) {
|
|
109
|
+
* console.log('Cache hit:', user.name);
|
|
110
|
+
* } else {
|
|
111
|
+
* console.log('Cache miss');
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
get<T>(key: string): T | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Check if a key exists in the cache.
|
|
118
|
+
*
|
|
119
|
+
* Returns false if key doesn't exist or entry has expired.
|
|
120
|
+
* Updates access order (moves entry to end as most recently used).
|
|
121
|
+
*
|
|
122
|
+
* @param key - Cache key
|
|
123
|
+
* @returns True if key exists and not expired
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* if (cache.has('user:123')) {
|
|
128
|
+
* const user = cache.get('user:123');
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
has(key: string): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Delete a key from the cache.
|
|
135
|
+
*
|
|
136
|
+
* Does nothing if key doesn't exist.
|
|
137
|
+
*
|
|
138
|
+
* @param key - Cache key to delete
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* cache.delete('user:123');
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
delete(key: string): void;
|
|
146
|
+
/**
|
|
147
|
+
* Clear all entries from the cache.
|
|
148
|
+
*
|
|
149
|
+
* Resets the cache but preserves statistics.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* cache.clear(); // Remove all cached data
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
clear(): void;
|
|
157
|
+
/**
|
|
158
|
+
* Get current cache size.
|
|
159
|
+
*
|
|
160
|
+
* @returns Number of entries in cache
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* console.log(`Cache contains ${cache.size()} entries`);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
size(): number;
|
|
168
|
+
/**
|
|
169
|
+
* Get cache statistics.
|
|
170
|
+
*
|
|
171
|
+
* Provides insight into cache performance:
|
|
172
|
+
* - Hit/miss counts
|
|
173
|
+
* - Hit rate percentage
|
|
174
|
+
* - Eviction count
|
|
175
|
+
* - Current size
|
|
176
|
+
*
|
|
177
|
+
* @returns Cache statistics object
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const stats = cache.getStats();
|
|
182
|
+
* console.log(`Hit rate: ${(stats.hitRate * 100).toFixed(1)}%`);
|
|
183
|
+
* console.log(`Evictions: ${stats.evictions}`);
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
getStats(): CacheStats;
|
|
187
|
+
/**
|
|
188
|
+
* Reset statistics counters.
|
|
189
|
+
*
|
|
190
|
+
* Clears hit/miss/eviction counts but preserves cached data.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* cache.resetStats(); // Start fresh statistics
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
resetStats(): void;
|
|
198
|
+
/**
|
|
199
|
+
* Check if an entry has expired based on TTL.
|
|
200
|
+
*
|
|
201
|
+
* @param entry - Cache entry to check
|
|
202
|
+
* @returns True if entry is expired
|
|
203
|
+
* @internal
|
|
204
|
+
*/
|
|
205
|
+
private isExpired;
|
|
206
|
+
/**
|
|
207
|
+
* Remove all expired entries from the cache.
|
|
208
|
+
*
|
|
209
|
+
* Called automatically by size() to keep cache clean.
|
|
210
|
+
*
|
|
211
|
+
* @internal
|
|
212
|
+
*/
|
|
213
|
+
private cleanupExpired;
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=QueryCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryCache.d.ts","sourceRoot":"","sources":["../../src/cache/QueryCache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;CACf;AAYD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAmC;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,KAAK,CAIX;IAEF;;;;;;;;;;;OAWG;gBACS,MAAM,GAAE,OAAO,CAAC,gBAAgB,CAAM;IAkBlD;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAsBnC;;;;;;;;;;;;;;;;;;OAkBG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAuBlC;;;;;;;;;;;;;;;OAeG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAoBzB;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIzB;;;;;;;;;OASG;IACH,KAAK,IAAI,IAAI;IAIb;;;;;;;;;OASG;IACH,IAAI,IAAI,MAAM;IAMd;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,IAAI,UAAU;IActB;;;;;;;;;OASG;IACH,UAAU,IAAI,IAAI;IAQlB;;;;;;OAMG;IACH,OAAO,CAAC,SAAS;IAKjB;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;CAavB"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QueryCache - LRU cache for database query results
|
|
3
|
+
*
|
|
4
|
+
* Provides an in-memory caching layer with:
|
|
5
|
+
* - LRU (Least Recently Used) eviction policy
|
|
6
|
+
* - TTL (Time To Live) for automatic expiration
|
|
7
|
+
* - Cache statistics (hits, misses, evictions, hit rate)
|
|
8
|
+
* - Smart invalidation support
|
|
9
|
+
*
|
|
10
|
+
* Use this to cache expensive database queries like conversation searches,
|
|
11
|
+
* file timelines, and decision lookups.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const cache = new QueryCache({ maxSize: 100, ttlMs: 60000 });
|
|
16
|
+
*
|
|
17
|
+
* // Store query result
|
|
18
|
+
* cache.set('conversations:all', conversations);
|
|
19
|
+
*
|
|
20
|
+
* // Retrieve from cache
|
|
21
|
+
* const cached = cache.get('conversations:all');
|
|
22
|
+
* if (cached) {
|
|
23
|
+
* return cached; // Cache hit
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* // Cache miss - query database
|
|
27
|
+
* const result = await queryDatabase();
|
|
28
|
+
* cache.set('conversations:all', result);
|
|
29
|
+
* return result;
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* LRU cache with TTL support for database query results.
|
|
34
|
+
*
|
|
35
|
+
* Uses a Map for O(1) access and maintains LRU order by moving
|
|
36
|
+
* accessed entries to the end of the Map.
|
|
37
|
+
*/
|
|
38
|
+
export class QueryCache {
|
|
39
|
+
cache;
|
|
40
|
+
config;
|
|
41
|
+
stats = {
|
|
42
|
+
hits: 0,
|
|
43
|
+
misses: 0,
|
|
44
|
+
evictions: 0,
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Create a new QueryCache.
|
|
48
|
+
*
|
|
49
|
+
* @param config - Cache configuration
|
|
50
|
+
* @throws {Error} If configuration is invalid
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // Create cache with 100 entries, 1 minute TTL
|
|
55
|
+
* const cache = new QueryCache({ maxSize: 100, ttlMs: 60000 });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
constructor(config = {}) {
|
|
59
|
+
// Default configuration
|
|
60
|
+
this.config = {
|
|
61
|
+
maxSize: config.maxSize ?? 100,
|
|
62
|
+
ttlMs: config.ttlMs ?? 300000, // 5 minutes default
|
|
63
|
+
};
|
|
64
|
+
// Validate configuration
|
|
65
|
+
if (this.config.maxSize <= 0) {
|
|
66
|
+
throw new Error("maxSize must be greater than 0");
|
|
67
|
+
}
|
|
68
|
+
if (this.config.ttlMs <= 0) {
|
|
69
|
+
throw new Error("ttlMs must be greater than 0");
|
|
70
|
+
}
|
|
71
|
+
this.cache = new Map();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Store a value in the cache.
|
|
75
|
+
*
|
|
76
|
+
* If the key already exists, updates the value and resets TTL.
|
|
77
|
+
* If cache is full, evicts the least recently used entry.
|
|
78
|
+
*
|
|
79
|
+
* @param key - Cache key
|
|
80
|
+
* @param value - Value to cache
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* cache.set('user:123', { id: 123, name: 'Alice' });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
set(key, value) {
|
|
88
|
+
// Remove old entry if exists (to update position)
|
|
89
|
+
if (this.cache.has(key)) {
|
|
90
|
+
this.cache.delete(key);
|
|
91
|
+
}
|
|
92
|
+
// Evict LRU entry if at capacity
|
|
93
|
+
if (this.cache.size >= this.config.maxSize) {
|
|
94
|
+
const firstKey = this.cache.keys().next().value;
|
|
95
|
+
if (firstKey !== undefined) {
|
|
96
|
+
this.cache.delete(firstKey);
|
|
97
|
+
this.stats.evictions++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Add new entry at end (most recently used)
|
|
101
|
+
this.cache.set(key, {
|
|
102
|
+
value: value,
|
|
103
|
+
timestamp: Date.now(),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Retrieve a value from the cache.
|
|
108
|
+
*
|
|
109
|
+
* Returns undefined if key doesn't exist or entry has expired.
|
|
110
|
+
* Updates access order (moves entry to end as most recently used).
|
|
111
|
+
*
|
|
112
|
+
* @param key - Cache key
|
|
113
|
+
* @returns Cached value or undefined
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const user = cache.get<User>('user:123');
|
|
118
|
+
* if (user) {
|
|
119
|
+
* console.log('Cache hit:', user.name);
|
|
120
|
+
* } else {
|
|
121
|
+
* console.log('Cache miss');
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
get(key) {
|
|
126
|
+
const entry = this.cache.get(key);
|
|
127
|
+
if (!entry) {
|
|
128
|
+
this.stats.misses++;
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
// Check if expired
|
|
132
|
+
if (this.isExpired(entry)) {
|
|
133
|
+
this.cache.delete(key);
|
|
134
|
+
this.stats.misses++;
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
// Move to end (most recently used)
|
|
138
|
+
this.cache.delete(key);
|
|
139
|
+
this.cache.set(key, entry);
|
|
140
|
+
this.stats.hits++;
|
|
141
|
+
return entry.value;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check if a key exists in the cache.
|
|
145
|
+
*
|
|
146
|
+
* Returns false if key doesn't exist or entry has expired.
|
|
147
|
+
* Updates access order (moves entry to end as most recently used).
|
|
148
|
+
*
|
|
149
|
+
* @param key - Cache key
|
|
150
|
+
* @returns True if key exists and not expired
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* if (cache.has('user:123')) {
|
|
155
|
+
* const user = cache.get('user:123');
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
has(key) {
|
|
160
|
+
const entry = this.cache.get(key);
|
|
161
|
+
if (!entry) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
// Check if expired
|
|
165
|
+
if (this.isExpired(entry)) {
|
|
166
|
+
this.cache.delete(key);
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
// Move to end (most recently used)
|
|
170
|
+
this.cache.delete(key);
|
|
171
|
+
this.cache.set(key, entry);
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Delete a key from the cache.
|
|
176
|
+
*
|
|
177
|
+
* Does nothing if key doesn't exist.
|
|
178
|
+
*
|
|
179
|
+
* @param key - Cache key to delete
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* cache.delete('user:123');
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
delete(key) {
|
|
187
|
+
this.cache.delete(key);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Clear all entries from the cache.
|
|
191
|
+
*
|
|
192
|
+
* Resets the cache but preserves statistics.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* cache.clear(); // Remove all cached data
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
clear() {
|
|
200
|
+
this.cache.clear();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get current cache size.
|
|
204
|
+
*
|
|
205
|
+
* @returns Number of entries in cache
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* console.log(`Cache contains ${cache.size()} entries`);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
size() {
|
|
213
|
+
// Clean up expired entries first
|
|
214
|
+
this.cleanupExpired();
|
|
215
|
+
return this.cache.size;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get cache statistics.
|
|
219
|
+
*
|
|
220
|
+
* Provides insight into cache performance:
|
|
221
|
+
* - Hit/miss counts
|
|
222
|
+
* - Hit rate percentage
|
|
223
|
+
* - Eviction count
|
|
224
|
+
* - Current size
|
|
225
|
+
*
|
|
226
|
+
* @returns Cache statistics object
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const stats = cache.getStats();
|
|
231
|
+
* console.log(`Hit rate: ${(stats.hitRate * 100).toFixed(1)}%`);
|
|
232
|
+
* console.log(`Evictions: ${stats.evictions}`);
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
getStats() {
|
|
236
|
+
const totalRequests = this.stats.hits + this.stats.misses;
|
|
237
|
+
const hitRate = totalRequests > 0 ? this.stats.hits / totalRequests : 0;
|
|
238
|
+
return {
|
|
239
|
+
hits: this.stats.hits,
|
|
240
|
+
misses: this.stats.misses,
|
|
241
|
+
evictions: this.stats.evictions,
|
|
242
|
+
hitRate,
|
|
243
|
+
size: this.cache.size,
|
|
244
|
+
maxSize: this.config.maxSize,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Reset statistics counters.
|
|
249
|
+
*
|
|
250
|
+
* Clears hit/miss/eviction counts but preserves cached data.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* cache.resetStats(); // Start fresh statistics
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
resetStats() {
|
|
258
|
+
this.stats = {
|
|
259
|
+
hits: 0,
|
|
260
|
+
misses: 0,
|
|
261
|
+
evictions: 0,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Check if an entry has expired based on TTL.
|
|
266
|
+
*
|
|
267
|
+
* @param entry - Cache entry to check
|
|
268
|
+
* @returns True if entry is expired
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
isExpired(entry) {
|
|
272
|
+
const age = Date.now() - entry.timestamp;
|
|
273
|
+
return age > this.config.ttlMs;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Remove all expired entries from the cache.
|
|
277
|
+
*
|
|
278
|
+
* Called automatically by size() to keep cache clean.
|
|
279
|
+
*
|
|
280
|
+
* @internal
|
|
281
|
+
*/
|
|
282
|
+
cleanupExpired() {
|
|
283
|
+
const keysToDelete = [];
|
|
284
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
285
|
+
if (this.isExpired(entry)) {
|
|
286
|
+
keysToDelete.push(key);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
for (const key of keysToDelete) {
|
|
290
|
+
this.cache.delete(key);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=QueryCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueryCache.js","sourceRoot":"","sources":["../../src/cache/QueryCache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAwCH;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IACb,KAAK,CAAmC;IAC/B,MAAM,CAAmB;IAClC,KAAK,GAAG;QACd,IAAI,EAAE,CAAC;QACP,MAAM,EAAE,CAAC;QACT,SAAS,EAAE,CAAC;KACb,CAAC;IAEF;;;;;;;;;;;OAWG;IACH,YAAY,SAAoC,EAAE;QAChD,wBAAwB;QACxB,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,GAAG;YAC9B,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,EAAE,oBAAoB;SACpD,CAAC;QAEF,yBAAyB;QACzB,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAI,GAAW,EAAE,KAAQ;QAC1B,kDAAkD;QAClD,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;Q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,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,QAAQ,CAAe;;IAqB/B;;OAEG;IACH,OAAO,CAAC,aAAa;
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH;;GAEG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,QAAQ,CAAe;;IAqB/B;;OAEG;IACH,OAAO,CAAC,aAAa;IAuGrB;;OAEG;IACG,KAAK;CAUZ"}
|
package/dist/mcp-server.js
CHANGED
|
@@ -76,6 +76,9 @@ export class ConversationMemoryServer {
|
|
|
76
76
|
case "find_similar_sessions":
|
|
77
77
|
result = await this.handlers.findSimilarSessions(args);
|
|
78
78
|
break;
|
|
79
|
+
case "recall_and_apply":
|
|
80
|
+
result = await this.handlers.recallAndApply(args);
|
|
81
|
+
break;
|
|
79
82
|
case "generate_documentation":
|
|
80
83
|
result = await this.handlers.generateDocumentation(args);
|
|
81
84
|
break;
|
package/dist/mcp-server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;A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,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAE7C,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACrE,OAAO,CAAC,KAAK,CAAC,mBAAmB,gBAAgB,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;QAEzE,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAErC,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC3D,CAAC;CACF"}
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Multi-pass JSONL Conversation Parser
|
|
3
|
-
*
|
|
2
|
+
* Multi-pass JSONL Conversation Parser for Claude Code history.
|
|
3
|
+
*
|
|
4
|
+
* This parser reads conversation history from Claude Code's storage locations
|
|
5
|
+
* (~/.claude/projects) and extracts structured data including messages, tool uses,
|
|
6
|
+
* file edits, and thinking blocks.
|
|
7
|
+
*
|
|
8
|
+
* The parser handles two directory structures:
|
|
9
|
+
* - Modern: ~/.claude/projects/{sanitized-path}
|
|
10
|
+
* - Legacy: ~/.claude/projects/{original-project-name}
|
|
11
|
+
*
|
|
12
|
+
* It performs a multi-pass parsing approach:
|
|
13
|
+
* 1. First pass: Extract conversations and messages
|
|
14
|
+
* 2. Second pass: Link tool uses and results
|
|
15
|
+
* 3. Third pass: Extract file edits from snapshots
|
|
16
|
+
* 4. Fourth pass: Extract thinking blocks
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const parser = new ConversationParser();
|
|
21
|
+
* const result = parser.parseProject('/path/to/project');
|
|
22
|
+
* console.log(`Parsed ${result.conversations.length} conversations`);
|
|
23
|
+
* console.log(`Found ${result.messages.length} messages`);
|
|
24
|
+
* console.log(`Extracted ${result.tool_uses.length} tool uses`);
|
|
25
|
+
* ```
|
|
4
26
|
*/
|
|
5
27
|
export interface ConversationMessage {
|
|
6
28
|
type: string;
|
|
@@ -89,18 +111,55 @@ export interface ThinkingBlock {
|
|
|
89
111
|
signature?: string;
|
|
90
112
|
timestamp: number;
|
|
91
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Result of parsing conversation history.
|
|
116
|
+
*
|
|
117
|
+
* Contains all extracted entities from conversation files.
|
|
118
|
+
*/
|
|
92
119
|
export interface ParseResult {
|
|
120
|
+
/** Parsed conversations with metadata */
|
|
93
121
|
conversations: Conversation[];
|
|
122
|
+
/** All messages from conversations */
|
|
94
123
|
messages: Message[];
|
|
124
|
+
/** Tool invocations extracted from assistant messages */
|
|
95
125
|
tool_uses: ToolUse[];
|
|
126
|
+
/** Results from tool executions */
|
|
96
127
|
tool_results: ToolResult[];
|
|
128
|
+
/** File edit records from snapshots */
|
|
97
129
|
file_edits: FileEdit[];
|
|
130
|
+
/** Thinking blocks (Claude's internal reasoning) */
|
|
98
131
|
thinking_blocks: ThinkingBlock[];
|
|
132
|
+
/** Folders that were actually indexed */
|
|
99
133
|
indexed_folders?: string[];
|
|
100
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Parser for Claude Code conversation history.
|
|
137
|
+
*
|
|
138
|
+
* Extracts structured data from JSONL conversation files stored in
|
|
139
|
+
* ~/.claude/projects. Handles both modern and legacy naming conventions.
|
|
140
|
+
*/
|
|
101
141
|
export declare class ConversationParser {
|
|
102
142
|
/**
|
|
103
|
-
* Parse all conversations for a project
|
|
143
|
+
* Parse all conversations for a project.
|
|
144
|
+
*
|
|
145
|
+
* Searches for conversation files in Claude's storage directories and
|
|
146
|
+
* parses them into structured entities. Supports filtering by session ID
|
|
147
|
+
* and handles both modern and legacy directory naming conventions.
|
|
148
|
+
*
|
|
149
|
+
* @param projectPath - Absolute path to the project
|
|
150
|
+
* @param sessionId - Optional session ID to filter for a single conversation
|
|
151
|
+
* @returns ParseResult containing all extracted entities
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const parser = new ConversationParser();
|
|
156
|
+
*
|
|
157
|
+
* // Parse all conversations
|
|
158
|
+
* const allResults = parser.parseProject('/Users/me/my-project');
|
|
159
|
+
*
|
|
160
|
+
* // Parse specific session
|
|
161
|
+
* const sessionResults = parser.parseProject('/Users/me/my-project', 'session-123');
|
|
162
|
+
* ```
|
|
104
163
|
*/
|
|
105
164
|
parseProject(projectPath: string, sessionId?: string): ParseResult;
|
|
106
165
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationParser.d.ts","sourceRoot":"","sources":["../../src/parsers/ConversationParser.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ConversationParser.d.ts","sourceRoot":"","sources":["../../src/parsers/ConversationParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAsCH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAA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