claude-conversation-memory-mcp 0.6.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/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/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/ToolHandlers.d.ts +525 -16
- package/dist/tools/ToolHandlers.d.ts.map +1 -1
- package/dist/tools/ToolHandlers.js +533 -24
- package/dist/tools/ToolHandlers.js.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
|
@@ -1,16 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Main Orchestrator - Coordinates all components
|
|
2
|
+
* Main Orchestrator - Coordinates all components for conversation memory indexing and retrieval.
|
|
3
|
+
*
|
|
4
|
+
* ConversationMemory is the primary interface for the conversation-memory-mcp system.
|
|
5
|
+
* It orchestrates parsing, storage, extraction, and search of Claude Code conversation history.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const memory = new ConversationMemory();
|
|
10
|
+
* await memory.indexConversations({
|
|
11
|
+
* projectPath: '/path/to/project',
|
|
12
|
+
* enableGitIntegration: true
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
3
15
|
*/
|
|
4
16
|
import { ConversationStorage } from "./storage/ConversationStorage.js";
|
|
5
17
|
import { SemanticSearch } from "./search/SemanticSearch.js";
|
|
18
|
+
/**
|
|
19
|
+
* Configuration options for indexing conversations.
|
|
20
|
+
*/
|
|
6
21
|
export interface IndexOptions {
|
|
22
|
+
/** Absolute path to the project directory to index */
|
|
7
23
|
projectPath: string;
|
|
24
|
+
/** Optional: Index only a specific session ID instead of all sessions */
|
|
8
25
|
sessionId?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to include thinking blocks in the index.
|
|
28
|
+
* Thinking blocks can be large and are excluded by default.
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
9
31
|
includeThinking?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Enable git integration to link commits to conversations.
|
|
34
|
+
* Requires the project to be a git repository.
|
|
35
|
+
* @default true
|
|
36
|
+
*/
|
|
10
37
|
enableGitIntegration?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Exclude MCP tool conversations from indexing.
|
|
40
|
+
* - `false`: Index all conversations (default)
|
|
41
|
+
* - `'self-only'`: Exclude only conversation-memory MCP conversations (prevents self-referential loops)
|
|
42
|
+
* - `'all-mcp'` or `true`: Exclude all MCP tool conversations
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
11
45
|
excludeMcpConversations?: boolean | 'self-only' | 'all-mcp';
|
|
46
|
+
/**
|
|
47
|
+
* List of specific MCP server names to exclude.
|
|
48
|
+
* More granular than `excludeMcpConversations`.
|
|
49
|
+
* @example ['conversation-memory', 'code-graph-rag']
|
|
50
|
+
*/
|
|
12
51
|
excludeMcpServers?: string[];
|
|
13
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Main orchestrator for conversation memory operations.
|
|
55
|
+
*
|
|
56
|
+
* Coordinates parsing, storage, extraction, and search across:
|
|
57
|
+
* - Conversation parsing from JSONL files
|
|
58
|
+
* - Decision, mistake, and requirement extraction
|
|
59
|
+
* - Git commit integration
|
|
60
|
+
* - Semantic search with embeddings
|
|
61
|
+
*/
|
|
14
62
|
export declare class ConversationMemory {
|
|
15
63
|
private sqliteManager;
|
|
16
64
|
private storage;
|
|
@@ -21,7 +69,39 @@ export declare class ConversationMemory {
|
|
|
21
69
|
private semanticSearch;
|
|
22
70
|
constructor();
|
|
23
71
|
/**
|
|
24
|
-
* Index conversations for a project
|
|
72
|
+
* Index conversations for a project.
|
|
73
|
+
*
|
|
74
|
+
* This is the main entry point for processing conversation history.
|
|
75
|
+
* It performs the following operations:
|
|
76
|
+
* 1. Parse conversation JSONL files from the project
|
|
77
|
+
* 2. Store conversations, messages, and tool interactions
|
|
78
|
+
* 3. Extract decisions, mistakes, and requirements
|
|
79
|
+
* 4. Link git commits (if enabled)
|
|
80
|
+
* 5. Generate semantic embeddings for search
|
|
81
|
+
*
|
|
82
|
+
* @param options - Configuration options for indexing
|
|
83
|
+
* @returns Result object containing:
|
|
84
|
+
* - `embeddings_generated`: Whether embeddings were successfully generated
|
|
85
|
+
* - `embedding_error`: Error message if embedding generation failed
|
|
86
|
+
* - `indexed_folders`: List of folders that were indexed
|
|
87
|
+
* - `database_path`: Path to the SQLite database
|
|
88
|
+
*
|
|
89
|
+
* @throws {Error} If project path doesn't exist or conversation files can't be parsed
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const result = await memory.indexConversations({
|
|
94
|
+
* projectPath: '/Users/me/my-project',
|
|
95
|
+
* enableGitIntegration: true,
|
|
96
|
+
* excludeMcpConversations: 'self-only'
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* if (result.embeddings_generated) {
|
|
100
|
+
* console.log('Indexed folders:', result.indexed_folders);
|
|
101
|
+
* } else {
|
|
102
|
+
* console.warn('Embeddings failed:', result.embedding_error);
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
25
105
|
*/
|
|
26
106
|
indexConversations(options: IndexOptions): Promise<{
|
|
27
107
|
embeddings_generated: boolean;
|
|
@@ -30,15 +110,55 @@ export declare class ConversationMemory {
|
|
|
30
110
|
database_path?: string;
|
|
31
111
|
}>;
|
|
32
112
|
/**
|
|
33
|
-
* Search conversations
|
|
113
|
+
* Search conversations using natural language query.
|
|
114
|
+
*
|
|
115
|
+
* Uses semantic search with embeddings if available, otherwise falls back to full-text search.
|
|
116
|
+
*
|
|
117
|
+
* @param query - Natural language search query
|
|
118
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
119
|
+
* @returns Array of search results with messages, conversations, and similarity scores
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const results = await memory.search('authentication bug fix', 5);
|
|
124
|
+
* results.forEach(r => {
|
|
125
|
+
* console.log(`${r.similarity}: ${r.snippet}`);
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
34
128
|
*/
|
|
35
129
|
search(query: string, limit?: number): Promise<import("./search/SemanticSearch.js").SearchResult[]>;
|
|
36
130
|
/**
|
|
37
|
-
* Search decisions
|
|
131
|
+
* Search for decisions using natural language query.
|
|
132
|
+
*
|
|
133
|
+
* Searches through extracted decisions to find relevant architectural choices and technical decisions.
|
|
134
|
+
*
|
|
135
|
+
* @param query - Natural language search query
|
|
136
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
137
|
+
* @returns Array of decision search results with similarity scores
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const decisions = await memory.searchDecisions('database choice', 3);
|
|
142
|
+
* decisions.forEach(d => {
|
|
143
|
+
* console.log(`Decision: ${d.decision.decision_text}`);
|
|
144
|
+
* console.log(`Rationale: ${d.decision.rationale}`);
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
38
147
|
*/
|
|
39
148
|
searchDecisions(query: string, limit?: number): Promise<import("./search/SemanticSearch.js").DecisionSearchResult[]>;
|
|
40
149
|
/**
|
|
41
|
-
* Get
|
|
150
|
+
* Get the timeline of changes for a specific file.
|
|
151
|
+
*
|
|
152
|
+
* Returns all edits, commits, and related conversations for a file across its history.
|
|
153
|
+
*
|
|
154
|
+
* @param filePath - Path to the file (relative to project root)
|
|
155
|
+
* @returns Timeline of file changes with conversations and commits
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const timeline = memory.getFileTimeline('src/index.ts');
|
|
160
|
+
* console.log(`${timeline.length} changes to this file`);
|
|
161
|
+
* ```
|
|
42
162
|
*/
|
|
43
163
|
getFileTimeline(filePath: string): {
|
|
44
164
|
file_path: string;
|
|
@@ -47,7 +167,16 @@ export declare class ConversationMemory {
|
|
|
47
167
|
decisions: import("./parsers/DecisionExtractor.js").Decision[];
|
|
48
168
|
};
|
|
49
169
|
/**
|
|
50
|
-
* Get statistics
|
|
170
|
+
* Get statistics about the indexed conversation data.
|
|
171
|
+
*
|
|
172
|
+
* @returns Object containing counts for conversations, messages, decisions, mistakes, and commits
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const stats = memory.getStats();
|
|
177
|
+
* console.log(`Indexed ${stats.conversations.count} conversations`);
|
|
178
|
+
* console.log(`Extracted ${stats.decisions.count} decisions`);
|
|
179
|
+
* ```
|
|
51
180
|
*/
|
|
52
181
|
getStats(): {
|
|
53
182
|
conversations: {
|
|
@@ -67,16 +196,28 @@ export declare class ConversationMemory {
|
|
|
67
196
|
};
|
|
68
197
|
};
|
|
69
198
|
/**
|
|
70
|
-
* Get storage instance
|
|
199
|
+
* Get the underlying storage instance for direct database access.
|
|
200
|
+
*
|
|
201
|
+
* Use with caution - prefer using the high-level methods when possible.
|
|
202
|
+
*
|
|
203
|
+
* @returns ConversationStorage instance
|
|
204
|
+
* @internal
|
|
71
205
|
*/
|
|
72
206
|
getStorage(): ConversationStorage;
|
|
73
207
|
/**
|
|
74
|
-
* Get semantic search instance
|
|
208
|
+
* Get the semantic search instance for advanced search operations.
|
|
209
|
+
*
|
|
210
|
+
* @returns SemanticSearch instance
|
|
211
|
+
* @internal
|
|
75
212
|
*/
|
|
76
213
|
getSemanticSearch(): SemanticSearch;
|
|
77
214
|
/**
|
|
78
|
-
* Filter MCP conversations from parse results
|
|
79
|
-
*
|
|
215
|
+
* Filter MCP conversations from parse results.
|
|
216
|
+
*
|
|
217
|
+
* Implements the exclusion logic for MCP tool conversations to prevent
|
|
218
|
+
* self-referential loops and reduce noise in the index.
|
|
219
|
+
*
|
|
220
|
+
* Strategy: Filter at MESSAGE level, not conversation level.
|
|
80
221
|
* - Keep all conversations
|
|
81
222
|
* - Exclude only messages that invoke specified MCP tools and their responses
|
|
82
223
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationMemory.d.ts","sourceRoot":"","sources":["../src/ConversationMemory.ts"],"names":[],"mappings":"AAAA
|
|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MAAW;IAI9C;;;;;;;;;;;;;;;;;OAiBG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW;IAIvD;;;;;;;;;;;;;OAaG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM;;;;;;IAIhC;;;;;;;;;;;OAWG;IACH,QAAQ;;;;;;;;;;;;;;;;;IAIR;;;;;;;OAOG;IACH,UAAU;IAIV;;;;;OAKG;IACH,iBAAiB;IAIjB;;;;;;;;;OASG;IACH,OAAO,CAAC,sBAAsB;CAqE/B"}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Main Orchestrator - Coordinates all components
|
|
2
|
+
* Main Orchestrator - Coordinates all components for conversation memory indexing and retrieval.
|
|
3
|
+
*
|
|
4
|
+
* ConversationMemory is the primary interface for the conversation-memory-mcp system.
|
|
5
|
+
* It orchestrates parsing, storage, extraction, and search of Claude Code conversation history.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const memory = new ConversationMemory();
|
|
10
|
+
* await memory.indexConversations({
|
|
11
|
+
* projectPath: '/path/to/project',
|
|
12
|
+
* enableGitIntegration: true
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
3
15
|
*/
|
|
4
16
|
import { getSQLiteManager } from "./storage/SQLiteManager.js";
|
|
5
17
|
import { ConversationStorage } from "./storage/ConversationStorage.js";
|
|
@@ -9,6 +21,15 @@ import { MistakeExtractor } from "./parsers/MistakeExtractor.js";
|
|
|
9
21
|
import { GitIntegrator } from "./parsers/GitIntegrator.js";
|
|
10
22
|
import { RequirementsExtractor } from "./parsers/RequirementsExtractor.js";
|
|
11
23
|
import { SemanticSearch } from "./search/SemanticSearch.js";
|
|
24
|
+
/**
|
|
25
|
+
* Main orchestrator for conversation memory operations.
|
|
26
|
+
*
|
|
27
|
+
* Coordinates parsing, storage, extraction, and search across:
|
|
28
|
+
* - Conversation parsing from JSONL files
|
|
29
|
+
* - Decision, mistake, and requirement extraction
|
|
30
|
+
* - Git commit integration
|
|
31
|
+
* - Semantic search with embeddings
|
|
32
|
+
*/
|
|
12
33
|
export class ConversationMemory {
|
|
13
34
|
sqliteManager;
|
|
14
35
|
storage;
|
|
@@ -20,6 +41,9 @@ export class ConversationMemory {
|
|
|
20
41
|
constructor() {
|
|
21
42
|
this.sqliteManager = getSQLiteManager();
|
|
22
43
|
this.storage = new ConversationStorage(this.sqliteManager);
|
|
44
|
+
// Enable caching by default for better performance
|
|
45
|
+
// Cache up to 100 query results for 5 minutes
|
|
46
|
+
this.storage.enableCache({ maxSize: 100, ttlMs: 300000 });
|
|
23
47
|
this.parser = new ConversationParser();
|
|
24
48
|
this.decisionExtractor = new DecisionExtractor();
|
|
25
49
|
this.mistakeExtractor = new MistakeExtractor();
|
|
@@ -27,7 +51,39 @@ export class ConversationMemory {
|
|
|
27
51
|
this.semanticSearch = new SemanticSearch(this.sqliteManager);
|
|
28
52
|
}
|
|
29
53
|
/**
|
|
30
|
-
* Index conversations for a project
|
|
54
|
+
* Index conversations for a project.
|
|
55
|
+
*
|
|
56
|
+
* This is the main entry point for processing conversation history.
|
|
57
|
+
* It performs the following operations:
|
|
58
|
+
* 1. Parse conversation JSONL files from the project
|
|
59
|
+
* 2. Store conversations, messages, and tool interactions
|
|
60
|
+
* 3. Extract decisions, mistakes, and requirements
|
|
61
|
+
* 4. Link git commits (if enabled)
|
|
62
|
+
* 5. Generate semantic embeddings for search
|
|
63
|
+
*
|
|
64
|
+
* @param options - Configuration options for indexing
|
|
65
|
+
* @returns Result object containing:
|
|
66
|
+
* - `embeddings_generated`: Whether embeddings were successfully generated
|
|
67
|
+
* - `embedding_error`: Error message if embedding generation failed
|
|
68
|
+
* - `indexed_folders`: List of folders that were indexed
|
|
69
|
+
* - `database_path`: Path to the SQLite database
|
|
70
|
+
*
|
|
71
|
+
* @throws {Error} If project path doesn't exist or conversation files can't be parsed
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const result = await memory.indexConversations({
|
|
76
|
+
* projectPath: '/Users/me/my-project',
|
|
77
|
+
* enableGitIntegration: true,
|
|
78
|
+
* excludeMcpConversations: 'self-only'
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* if (result.embeddings_generated) {
|
|
82
|
+
* console.log('Indexed folders:', result.indexed_folders);
|
|
83
|
+
* } else {
|
|
84
|
+
* console.warn('Embeddings failed:', result.embedding_error);
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
31
87
|
*/
|
|
32
88
|
async indexConversations(options) {
|
|
33
89
|
console.log("\n=== Indexing Conversations ===");
|
|
@@ -114,44 +170,105 @@ export class ConversationMemory {
|
|
|
114
170
|
};
|
|
115
171
|
}
|
|
116
172
|
/**
|
|
117
|
-
* Search conversations
|
|
173
|
+
* Search conversations using natural language query.
|
|
174
|
+
*
|
|
175
|
+
* Uses semantic search with embeddings if available, otherwise falls back to full-text search.
|
|
176
|
+
*
|
|
177
|
+
* @param query - Natural language search query
|
|
178
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
179
|
+
* @returns Array of search results with messages, conversations, and similarity scores
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const results = await memory.search('authentication bug fix', 5);
|
|
184
|
+
* results.forEach(r => {
|
|
185
|
+
* console.log(`${r.similarity}: ${r.snippet}`);
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
118
188
|
*/
|
|
119
189
|
async search(query, limit = 10) {
|
|
120
190
|
return this.semanticSearch.searchConversations(query, limit);
|
|
121
191
|
}
|
|
122
192
|
/**
|
|
123
|
-
* Search decisions
|
|
193
|
+
* Search for decisions using natural language query.
|
|
194
|
+
*
|
|
195
|
+
* Searches through extracted decisions to find relevant architectural choices and technical decisions.
|
|
196
|
+
*
|
|
197
|
+
* @param query - Natural language search query
|
|
198
|
+
* @param limit - Maximum number of results to return (default: 10)
|
|
199
|
+
* @returns Array of decision search results with similarity scores
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const decisions = await memory.searchDecisions('database choice', 3);
|
|
204
|
+
* decisions.forEach(d => {
|
|
205
|
+
* console.log(`Decision: ${d.decision.decision_text}`);
|
|
206
|
+
* console.log(`Rationale: ${d.decision.rationale}`);
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
124
209
|
*/
|
|
125
210
|
async searchDecisions(query, limit = 10) {
|
|
126
211
|
return this.semanticSearch.searchDecisions(query, limit);
|
|
127
212
|
}
|
|
128
213
|
/**
|
|
129
|
-
* Get
|
|
214
|
+
* Get the timeline of changes for a specific file.
|
|
215
|
+
*
|
|
216
|
+
* Returns all edits, commits, and related conversations for a file across its history.
|
|
217
|
+
*
|
|
218
|
+
* @param filePath - Path to the file (relative to project root)
|
|
219
|
+
* @returns Timeline of file changes with conversations and commits
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const timeline = memory.getFileTimeline('src/index.ts');
|
|
224
|
+
* console.log(`${timeline.length} changes to this file`);
|
|
225
|
+
* ```
|
|
130
226
|
*/
|
|
131
227
|
getFileTimeline(filePath) {
|
|
132
228
|
return this.storage.getFileTimeline(filePath);
|
|
133
229
|
}
|
|
134
230
|
/**
|
|
135
|
-
* Get statistics
|
|
231
|
+
* Get statistics about the indexed conversation data.
|
|
232
|
+
*
|
|
233
|
+
* @returns Object containing counts for conversations, messages, decisions, mistakes, and commits
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const stats = memory.getStats();
|
|
238
|
+
* console.log(`Indexed ${stats.conversations.count} conversations`);
|
|
239
|
+
* console.log(`Extracted ${stats.decisions.count} decisions`);
|
|
240
|
+
* ```
|
|
136
241
|
*/
|
|
137
242
|
getStats() {
|
|
138
243
|
return this.storage.getStats();
|
|
139
244
|
}
|
|
140
245
|
/**
|
|
141
|
-
* Get storage instance
|
|
246
|
+
* Get the underlying storage instance for direct database access.
|
|
247
|
+
*
|
|
248
|
+
* Use with caution - prefer using the high-level methods when possible.
|
|
249
|
+
*
|
|
250
|
+
* @returns ConversationStorage instance
|
|
251
|
+
* @internal
|
|
142
252
|
*/
|
|
143
253
|
getStorage() {
|
|
144
254
|
return this.storage;
|
|
145
255
|
}
|
|
146
256
|
/**
|
|
147
|
-
* Get semantic search instance
|
|
257
|
+
* Get the semantic search instance for advanced search operations.
|
|
258
|
+
*
|
|
259
|
+
* @returns SemanticSearch instance
|
|
260
|
+
* @internal
|
|
148
261
|
*/
|
|
149
262
|
getSemanticSearch() {
|
|
150
263
|
return this.semanticSearch;
|
|
151
264
|
}
|
|
152
265
|
/**
|
|
153
|
-
* Filter MCP conversations from parse results
|
|
154
|
-
*
|
|
266
|
+
* Filter MCP conversations from parse results.
|
|
267
|
+
*
|
|
268
|
+
* Implements the exclusion logic for MCP tool conversations to prevent
|
|
269
|
+
* self-referential loops and reduce noise in the index.
|
|
270
|
+
*
|
|
271
|
+
* Strategy: Filter at MESSAGE level, not conversation level.
|
|
155
272
|
* - Keep all conversations
|
|
156
273
|
* - Exclude only messages that invoke specified MCP tools and their responses
|
|
157
274
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationMemory.js","sourceRoot":"","sources":["../src/ConversationMemory.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ConversationMemory.js","sourceRoot":"","sources":["../src/ConversationMemory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAiB,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAoB,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,M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AAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACtE,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;YACvF,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,sBAAsB;YACrD,eAAe,EAAE,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;YAC5F,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,2BAA2B;SACrE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -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;I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