@pcircle/memesh 2.9.1 → 2.9.3
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.de.md +119 -78
- package/README.es.md +116 -75
- package/README.fr.md +116 -75
- package/README.id.md +115 -74
- package/README.ja.md +111 -70
- package/README.ko.md +116 -75
- package/README.md +113 -72
- package/README.th.md +118 -77
- package/README.vi.md +116 -75
- package/README.zh-CN.md +120 -79
- package/README.zh-TW.md +116 -75
- package/dist/core/GitCommandParser.d.ts +11 -0
- package/dist/core/GitCommandParser.d.ts.map +1 -0
- package/dist/core/GitCommandParser.js +43 -0
- package/dist/core/GitCommandParser.js.map +1 -0
- package/dist/core/HookIntegration.d.ts +0 -3
- package/dist/core/HookIntegration.d.ts.map +1 -1
- package/dist/core/HookIntegration.js +6 -30
- package/dist/core/HookIntegration.js.map +1 -1
- package/dist/embeddings/EmbeddingService.d.ts +3 -0
- package/dist/embeddings/EmbeddingService.d.ts.map +1 -1
- package/dist/embeddings/EmbeddingService.js +32 -6
- package/dist/embeddings/EmbeddingService.js.map +1 -1
- package/dist/embeddings/InMemoryVectorAdapter.d.ts +15 -0
- package/dist/embeddings/InMemoryVectorAdapter.d.ts.map +1 -0
- package/dist/embeddings/InMemoryVectorAdapter.js +58 -0
- package/dist/embeddings/InMemoryVectorAdapter.js.map +1 -0
- package/dist/embeddings/SqliteVecAdapter.d.ts +15 -0
- package/dist/embeddings/SqliteVecAdapter.d.ts.map +1 -0
- package/dist/embeddings/SqliteVecAdapter.js +107 -0
- package/dist/embeddings/SqliteVecAdapter.js.map +1 -0
- package/dist/embeddings/VectorExtension.d.ts +2 -4
- package/dist/embeddings/VectorExtension.d.ts.map +1 -1
- package/dist/embeddings/VectorExtension.js.map +1 -1
- package/dist/embeddings/VectorSearchAdapter.d.ts +17 -0
- package/dist/embeddings/VectorSearchAdapter.d.ts.map +1 -0
- package/dist/embeddings/VectorSearchAdapter.js +2 -0
- package/dist/embeddings/VectorSearchAdapter.js.map +1 -0
- package/dist/embeddings/index.d.ts +6 -1
- package/dist/embeddings/index.d.ts.map +1 -1
- package/dist/embeddings/index.js +4 -1
- package/dist/embeddings/index.js.map +1 -1
- package/dist/knowledge-graph/ContentHasher.d.ts +4 -0
- package/dist/knowledge-graph/ContentHasher.d.ts.map +1 -0
- package/dist/knowledge-graph/ContentHasher.js +8 -0
- package/dist/knowledge-graph/ContentHasher.js.map +1 -0
- package/dist/knowledge-graph/KGSearchEngine.d.ts +36 -0
- package/dist/knowledge-graph/KGSearchEngine.d.ts.map +1 -0
- package/dist/knowledge-graph/KGSearchEngine.js +257 -0
- package/dist/knowledge-graph/KGSearchEngine.js.map +1 -0
- package/dist/knowledge-graph/index.d.ts +18 -7
- package/dist/knowledge-graph/index.d.ts.map +1 -1
- package/dist/knowledge-graph/index.js +147 -242
- package/dist/knowledge-graph/index.js.map +1 -1
- package/dist/mcp/ServerInitializer.d.ts.map +1 -1
- package/dist/mcp/ServerInitializer.js +1 -1
- package/dist/mcp/ServerInitializer.js.map +1 -1
- package/dist/mcp/StdinBufferManager.d.ts +11 -0
- package/dist/mcp/StdinBufferManager.d.ts.map +1 -0
- package/dist/mcp/StdinBufferManager.js +62 -0
- package/dist/mcp/StdinBufferManager.js.map +1 -0
- package/dist/mcp/daemon/StdioProxyClient.d.ts.map +1 -1
- package/dist/mcp/daemon/StdioProxyClient.js +6 -0
- package/dist/mcp/daemon/StdioProxyClient.js.map +1 -1
- package/dist/mcp/handlers/HookToolHandler.d.ts +10 -0
- package/dist/mcp/handlers/HookToolHandler.d.ts.map +1 -0
- package/dist/mcp/handlers/HookToolHandler.js +92 -0
- package/dist/mcp/handlers/HookToolHandler.js.map +1 -0
- package/dist/mcp/handlers/MemoryToolHandler.d.ts +21 -0
- package/dist/mcp/handlers/MemoryToolHandler.d.ts.map +1 -0
- package/dist/mcp/handlers/MemoryToolHandler.js +430 -0
- package/dist/mcp/handlers/MemoryToolHandler.js.map +1 -0
- package/dist/mcp/handlers/SystemToolHandler.d.ts +14 -0
- package/dist/mcp/handlers/SystemToolHandler.d.ts.map +1 -0
- package/dist/mcp/handlers/SystemToolHandler.js +224 -0
- package/dist/mcp/handlers/SystemToolHandler.js.map +1 -0
- package/dist/mcp/handlers/ToolHandlers.d.ts +4 -17
- package/dist/mcp/handlers/ToolHandlers.d.ts.map +1 -1
- package/dist/mcp/handlers/ToolHandlers.js +19 -689
- package/dist/mcp/handlers/ToolHandlers.js.map +1 -1
- package/dist/mcp/handlers/index.d.ts +3 -0
- package/dist/mcp/handlers/index.d.ts.map +1 -1
- package/dist/mcp/handlers/index.js +3 -0
- package/dist/mcp/handlers/index.js.map +1 -1
- package/dist/mcp/server-bootstrap.js +24 -59
- package/dist/mcp/server-bootstrap.js.map +1 -1
- package/dist/mcp/tools/create-entities.d.ts.map +1 -1
- package/dist/mcp/tools/create-entities.js +18 -24
- package/dist/mcp/tools/create-entities.js.map +1 -1
- package/dist/memory/MemorySearchEngine.d.ts +17 -0
- package/dist/memory/MemorySearchEngine.d.ts.map +1 -0
- package/dist/memory/MemorySearchEngine.js +88 -0
- package/dist/memory/MemorySearchEngine.js.map +1 -0
- package/dist/memory/ProactiveRecaller.d.ts +26 -0
- package/dist/memory/ProactiveRecaller.d.ts.map +1 -0
- package/dist/memory/ProactiveRecaller.js +96 -0
- package/dist/memory/ProactiveRecaller.js.map +1 -0
- package/dist/memory/UnifiedMemoryStore.d.ts +1 -0
- package/dist/memory/UnifiedMemoryStore.d.ts.map +1 -1
- package/dist/memory/UnifiedMemoryStore.js +7 -63
- package/dist/memory/UnifiedMemoryStore.js.map +1 -1
- package/dist/memory/index.d.ts +3 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +2 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/tracing/index.d.ts +0 -1
- package/dist/utils/tracing/index.d.ts.map +1 -1
- package/dist/utils/tracing/index.js +0 -1
- package/dist/utils/tracing/index.js.map +1 -1
- package/package.json +2 -11
- package/plugin.json +1 -1
- package/scripts/hooks/__tests__/post-tool-use-recall.test.js +192 -0
- package/scripts/hooks/__tests__/session-start-recall.test.js +86 -0
- package/scripts/hooks/post-tool-use-recall-utils.js +74 -0
- package/scripts/hooks/post-tool-use.js +79 -0
- package/scripts/hooks/session-start-recall-utils.js +40 -0
- package/scripts/hooks/session-start.js +66 -0
|
@@ -1,711 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { MistakePatternEngine } from '../../memory/MistakePatternEngine.js';
|
|
5
|
-
import { UserPreferenceEngine } from '../../memory/UserPreferenceEngine.js';
|
|
6
|
-
import { recallMemoryTool } from '../tools/recall-memory.js';
|
|
7
|
-
import { createEntitiesTool } from '../tools/create-entities.js';
|
|
8
|
-
import { addObservationsTool } from '../tools/add-observations.js';
|
|
9
|
-
import { createRelationsTool } from '../tools/create-relations.js';
|
|
10
|
-
import { generateTestsTool } from '../tools/generate-tests.js';
|
|
11
|
-
import { handleBuddyRecordMistake } from './BuddyRecordMistake.js';
|
|
12
|
-
import { handleError, logError } from '../../utils/errorHandler.js';
|
|
13
|
-
import { ListSkillsInputSchema, UninstallInputSchema, HookToolUseInputSchema, RecallMemoryInputSchema, CreateEntitiesInputSchema, AddObservationsInputSchema, CreateRelationsInputSchema, GenerateTestsInputSchema, formatValidationError, } from '../validation.js';
|
|
1
|
+
import { MemoryToolHandler } from './MemoryToolHandler.js';
|
|
2
|
+
import { SystemToolHandler } from './SystemToolHandler.js';
|
|
3
|
+
import { HookToolHandler } from './HookToolHandler.js';
|
|
14
4
|
export class ToolHandlers {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
checkpointDetector
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ui;
|
|
23
|
-
samplingClient;
|
|
24
|
-
memoryRateLimiter;
|
|
25
|
-
unifiedMemoryStore;
|
|
26
|
-
mistakePatternEngine;
|
|
27
|
-
userPreferenceEngine;
|
|
28
|
-
constructor(agentRegistry, skillManager, uninstallManager, checkpointDetector, hookIntegration, projectMemoryManager, knowledgeGraph, ui, samplingClient, unifiedMemoryStore) {
|
|
29
|
-
this.agentRegistry = agentRegistry;
|
|
30
|
-
this.skillManager = skillManager;
|
|
31
|
-
this.uninstallManager = uninstallManager;
|
|
32
|
-
this.checkpointDetector = checkpointDetector;
|
|
33
|
-
this.hookIntegration = hookIntegration;
|
|
34
|
-
this.projectMemoryManager = projectMemoryManager;
|
|
35
|
-
this.knowledgeGraph = knowledgeGraph;
|
|
36
|
-
this.ui = ui;
|
|
37
|
-
this.samplingClient = samplingClient;
|
|
38
|
-
this.memoryRateLimiter = new RateLimiter({ requestsPerMinute: 10 });
|
|
39
|
-
this.unifiedMemoryStore = unifiedMemoryStore;
|
|
40
|
-
this.mistakePatternEngine = unifiedMemoryStore ? new MistakePatternEngine(unifiedMemoryStore) : undefined;
|
|
41
|
-
this.userPreferenceEngine = unifiedMemoryStore ? new UserPreferenceEngine(unifiedMemoryStore) : undefined;
|
|
42
|
-
}
|
|
43
|
-
isCloudOnlyMode() {
|
|
44
|
-
return this.knowledgeGraph === undefined || this.projectMemoryManager === undefined;
|
|
45
|
-
}
|
|
46
|
-
cloudOnlyModeError(toolName) {
|
|
47
|
-
return {
|
|
48
|
-
content: [
|
|
49
|
-
{
|
|
50
|
-
type: 'text',
|
|
51
|
-
text: `❌ Tool '${toolName}' is not available in cloud-only mode.\n\n` +
|
|
52
|
-
`This MCP server is running without local SQLite storage (better-sqlite3 unavailable).\n\n` +
|
|
53
|
-
`To use local memory tools:\n` +
|
|
54
|
-
`1. Install better-sqlite3: npm install better-sqlite3\n` +
|
|
55
|
-
`2. Restart the MCP server\n\n` +
|
|
56
|
-
`Local SQLite storage is required for memory features.`,
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
isError: true,
|
|
60
|
-
};
|
|
5
|
+
memoryHandler;
|
|
6
|
+
systemHandler;
|
|
7
|
+
hookHandler;
|
|
8
|
+
constructor(skillManager, uninstallManager, checkpointDetector, hookIntegration, projectMemoryManager, knowledgeGraph, _ui, samplingClient, unifiedMemoryStore) {
|
|
9
|
+
this.memoryHandler = new MemoryToolHandler(knowledgeGraph, projectMemoryManager, unifiedMemoryStore);
|
|
10
|
+
this.systemHandler = new SystemToolHandler(skillManager, uninstallManager, samplingClient);
|
|
11
|
+
this.hookHandler = new HookToolHandler(checkpointDetector, hookIntegration);
|
|
61
12
|
}
|
|
62
13
|
async handleListSkills(args) {
|
|
63
|
-
|
|
64
|
-
let validatedInput;
|
|
65
|
-
try {
|
|
66
|
-
validatedInput = ListSkillsInputSchema.parse(args);
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
if (error instanceof z.ZodError) {
|
|
70
|
-
throw new ValidationError(formatValidationError(error), {
|
|
71
|
-
component: 'ToolHandlers',
|
|
72
|
-
method: 'handleListSkills',
|
|
73
|
-
schema: 'ListSkillsInputSchema',
|
|
74
|
-
providedArgs: args,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
const filter = validatedInput.filter || 'all';
|
|
80
|
-
let skills;
|
|
81
|
-
let title;
|
|
82
|
-
switch (filter) {
|
|
83
|
-
case 'claude-code-buddy':
|
|
84
|
-
skills = await this.skillManager.listSmartAgentsSkills();
|
|
85
|
-
title = 'MeMesh Skills (sa: prefix)';
|
|
86
|
-
break;
|
|
87
|
-
case 'user':
|
|
88
|
-
skills = await this.skillManager.listUserSkills();
|
|
89
|
-
title = 'User Skills';
|
|
90
|
-
break;
|
|
91
|
-
case 'all':
|
|
92
|
-
default:
|
|
93
|
-
const allSkillsMetadata = await this.skillManager.listAllSkills();
|
|
94
|
-
skills = allSkillsMetadata.map(s => s.name);
|
|
95
|
-
title = 'All Skills';
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
let output = `${title}\n`;
|
|
99
|
-
output += '='.repeat(60) + '\n\n';
|
|
100
|
-
if (skills.length === 0) {
|
|
101
|
-
output += ' No skills found.\n\n';
|
|
102
|
-
if (filter === 'claude-code-buddy') {
|
|
103
|
-
output += 'MeMesh can generate skills automatically.\n';
|
|
104
|
-
output += 'Skills will appear here once generated.\n';
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
output += `Total: ${skills.length} skill${skills.length === 1 ? '' : 's'}\n\n`;
|
|
109
|
-
const saSkills = skills.filter(s => s.startsWith('sa:'));
|
|
110
|
-
const userSkills = skills.filter(s => !s.startsWith('sa:'));
|
|
111
|
-
if (filter === 'all') {
|
|
112
|
-
if (saSkills.length > 0) {
|
|
113
|
-
output += 'MeMesh Skills:\n';
|
|
114
|
-
output += '-'.repeat(60) + '\n';
|
|
115
|
-
saSkills.forEach(skill => {
|
|
116
|
-
output += ` - ${skill}\n`;
|
|
117
|
-
});
|
|
118
|
-
output += '\n';
|
|
119
|
-
}
|
|
120
|
-
if (userSkills.length > 0) {
|
|
121
|
-
output += 'User Skills:\n';
|
|
122
|
-
output += '-'.repeat(60) + '\n';
|
|
123
|
-
userSkills.forEach(skill => {
|
|
124
|
-
output += ` - ${skill}\n`;
|
|
125
|
-
});
|
|
126
|
-
output += '\n';
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
skills.forEach(skill => {
|
|
131
|
-
output += ` - ${skill}\n`;
|
|
132
|
-
});
|
|
133
|
-
output += '\n';
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
output += '='.repeat(60) + '\n';
|
|
137
|
-
output += '\nUsage:\n';
|
|
138
|
-
output += ' - buddy_skills - List all skills\n';
|
|
139
|
-
output += ' - buddy_skills --filter claude-code-buddy - List only sa: skills\n';
|
|
140
|
-
output += ' - buddy_skills --filter user - List only user skills\n';
|
|
141
|
-
output += '\nSkill Naming Convention:\n';
|
|
142
|
-
output += ' - sa:<name> - MeMesh generated skills\n';
|
|
143
|
-
output += ' - <name> - User-installed skills\n';
|
|
144
|
-
return {
|
|
145
|
-
content: [
|
|
146
|
-
{
|
|
147
|
-
type: 'text',
|
|
148
|
-
text: output,
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
logError(error, {
|
|
155
|
-
component: 'ToolHandlers',
|
|
156
|
-
method: 'handleListSkills',
|
|
157
|
-
operation: 'listing skills',
|
|
158
|
-
data: { filter: args?.filter },
|
|
159
|
-
});
|
|
160
|
-
const handled = handleError(error, {
|
|
161
|
-
component: 'ToolHandlers',
|
|
162
|
-
method: 'handleListSkills',
|
|
163
|
-
});
|
|
164
|
-
return {
|
|
165
|
-
content: [
|
|
166
|
-
{
|
|
167
|
-
type: 'text',
|
|
168
|
-
text: `List skills failed: ${handled.message}`,
|
|
169
|
-
},
|
|
170
|
-
],
|
|
171
|
-
};
|
|
172
|
-
}
|
|
14
|
+
return this.systemHandler.handleListSkills(args);
|
|
173
15
|
}
|
|
174
16
|
async handleUninstall(args) {
|
|
175
|
-
|
|
176
|
-
let validatedInput;
|
|
177
|
-
try {
|
|
178
|
-
validatedInput = UninstallInputSchema.parse(args);
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
if (error instanceof z.ZodError) {
|
|
182
|
-
throw new ValidationError(formatValidationError(error), {
|
|
183
|
-
component: 'ToolHandlers',
|
|
184
|
-
method: 'handleUninstall',
|
|
185
|
-
schema: 'UninstallInputSchema',
|
|
186
|
-
providedArgs: args,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
const report = await this.uninstallManager.uninstall(validatedInput);
|
|
192
|
-
const formattedReport = this.uninstallManager.formatReport(report);
|
|
193
|
-
return {
|
|
194
|
-
content: [
|
|
195
|
-
{
|
|
196
|
-
type: 'text',
|
|
197
|
-
text: formattedReport,
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
logError(error, {
|
|
204
|
-
component: 'ToolHandlers',
|
|
205
|
-
method: 'handleUninstall',
|
|
206
|
-
operation: 'uninstalling MeMesh',
|
|
207
|
-
data: { options: args },
|
|
208
|
-
});
|
|
209
|
-
const handled = handleError(error, {
|
|
210
|
-
component: 'ToolHandlers',
|
|
211
|
-
method: 'handleUninstall',
|
|
212
|
-
});
|
|
213
|
-
return {
|
|
214
|
-
content: [
|
|
215
|
-
{
|
|
216
|
-
type: 'text',
|
|
217
|
-
text: `Uninstall failed: ${handled.message}`,
|
|
218
|
-
},
|
|
219
|
-
],
|
|
220
|
-
};
|
|
221
|
-
}
|
|
17
|
+
return this.systemHandler.handleUninstall(args);
|
|
222
18
|
}
|
|
223
19
|
async handleHookToolUse(args) {
|
|
224
|
-
|
|
225
|
-
return this.cloudOnlyModeError('hook-tool-use');
|
|
226
|
-
}
|
|
227
|
-
try {
|
|
228
|
-
let validatedInput;
|
|
229
|
-
try {
|
|
230
|
-
validatedInput = HookToolUseInputSchema.parse(args);
|
|
231
|
-
}
|
|
232
|
-
catch (error) {
|
|
233
|
-
if (error instanceof z.ZodError) {
|
|
234
|
-
throw new ValidationError(formatValidationError(error), {
|
|
235
|
-
component: 'ToolHandlers',
|
|
236
|
-
method: 'handleHookToolUse',
|
|
237
|
-
schema: 'HookToolUseInputSchema',
|
|
238
|
-
providedArgs: args,
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
await this.hookIntegration.processToolUse({
|
|
244
|
-
toolName: validatedInput.toolName,
|
|
245
|
-
arguments: validatedInput.arguments,
|
|
246
|
-
success: validatedInput.success,
|
|
247
|
-
duration: validatedInput.duration,
|
|
248
|
-
tokensUsed: validatedInput.tokensUsed,
|
|
249
|
-
output: validatedInput.output,
|
|
250
|
-
});
|
|
251
|
-
return {
|
|
252
|
-
content: [
|
|
253
|
-
{
|
|
254
|
-
type: 'text',
|
|
255
|
-
text: JSON.stringify({ success: true }, null, 2),
|
|
256
|
-
},
|
|
257
|
-
],
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
catch (error) {
|
|
261
|
-
logError(error, {
|
|
262
|
-
component: 'ToolHandlers',
|
|
263
|
-
method: 'handleHookToolUse',
|
|
264
|
-
operation: 'processing hook tool use',
|
|
265
|
-
data: { toolName: args?.toolName },
|
|
266
|
-
});
|
|
267
|
-
const handled = handleError(error, {
|
|
268
|
-
component: 'ToolHandlers',
|
|
269
|
-
method: 'handleHookToolUse',
|
|
270
|
-
});
|
|
271
|
-
return {
|
|
272
|
-
content: [
|
|
273
|
-
{
|
|
274
|
-
type: 'text',
|
|
275
|
-
text: `Hook processing failed: ${handled.message}`,
|
|
276
|
-
},
|
|
277
|
-
],
|
|
278
|
-
};
|
|
279
|
-
}
|
|
20
|
+
return this.hookHandler.handleHookToolUse(args, this.memoryHandler.isCloudOnlyMode(), (toolName) => this.memoryHandler.cloudOnlyModeError(toolName));
|
|
280
21
|
}
|
|
281
22
|
async handleRecallMemory(args) {
|
|
282
|
-
|
|
283
|
-
return this.cloudOnlyModeError('recall-memory');
|
|
284
|
-
}
|
|
285
|
-
if (!this.memoryRateLimiter.consume()) {
|
|
286
|
-
throw new OperationError('Memory operation rate limit exceeded. Please try again later.', {
|
|
287
|
-
component: 'ToolHandlers',
|
|
288
|
-
method: 'handleRecallMemory',
|
|
289
|
-
rateLimitStatus: this.memoryRateLimiter.getStatus(),
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
try {
|
|
293
|
-
let validatedInput;
|
|
294
|
-
try {
|
|
295
|
-
validatedInput = RecallMemoryInputSchema.parse(args);
|
|
296
|
-
}
|
|
297
|
-
catch (error) {
|
|
298
|
-
if (error instanceof z.ZodError) {
|
|
299
|
-
throw new ValidationError(formatValidationError(error), {
|
|
300
|
-
component: 'ToolHandlers',
|
|
301
|
-
method: 'handleRecallMemory',
|
|
302
|
-
schema: 'RecallMemoryInputSchema',
|
|
303
|
-
providedArgs: args,
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
throw error;
|
|
307
|
-
}
|
|
308
|
-
const result = await recallMemoryTool.handler(validatedInput, this.projectMemoryManager);
|
|
309
|
-
let text = 'Project Memory Recall\n';
|
|
310
|
-
text += '='.repeat(60) + '\n\n';
|
|
311
|
-
if (result.memories.length === 0) {
|
|
312
|
-
text += 'No memories found.\n\n';
|
|
313
|
-
text += 'Memories will be created as you work on the project.\n';
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
text += `Found ${result.memories.length} recent memories:\n\n`;
|
|
317
|
-
result.memories.forEach((memory, index) => {
|
|
318
|
-
text += `${index + 1}. ${memory.type}\n`;
|
|
319
|
-
if (memory.timestamp) {
|
|
320
|
-
text += ` Timestamp: ${memory.timestamp}\n`;
|
|
321
|
-
}
|
|
322
|
-
if (memory.observations && memory.observations.length > 0) {
|
|
323
|
-
text += ' Observations:\n';
|
|
324
|
-
memory.observations.forEach(obs => {
|
|
325
|
-
text += ` - ${obs}\n`;
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
text += '\n';
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
text += '='.repeat(60) + '\n';
|
|
332
|
-
return {
|
|
333
|
-
content: [
|
|
334
|
-
{
|
|
335
|
-
type: 'text',
|
|
336
|
-
text,
|
|
337
|
-
},
|
|
338
|
-
],
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
catch (error) {
|
|
342
|
-
logError(error, {
|
|
343
|
-
component: 'ToolHandlers',
|
|
344
|
-
method: 'handleRecallMemory',
|
|
345
|
-
operation: 'recalling project memory',
|
|
346
|
-
data: { query: args?.query, limit: args?.limit },
|
|
347
|
-
});
|
|
348
|
-
const handled = handleError(error, {
|
|
349
|
-
component: 'ToolHandlers',
|
|
350
|
-
method: 'handleRecallMemory',
|
|
351
|
-
});
|
|
352
|
-
return {
|
|
353
|
-
content: [
|
|
354
|
-
{
|
|
355
|
-
type: 'text',
|
|
356
|
-
text: `Failed to recall memory: ${handled.message}`,
|
|
357
|
-
},
|
|
358
|
-
],
|
|
359
|
-
};
|
|
360
|
-
}
|
|
23
|
+
return this.memoryHandler.handleRecallMemory(args);
|
|
361
24
|
}
|
|
362
25
|
async handleCreateEntities(args) {
|
|
363
|
-
|
|
364
|
-
return this.cloudOnlyModeError('create-entities');
|
|
365
|
-
}
|
|
366
|
-
if (!this.memoryRateLimiter.consume()) {
|
|
367
|
-
throw new OperationError('Memory operation rate limit exceeded. Please try again later.', {
|
|
368
|
-
component: 'ToolHandlers',
|
|
369
|
-
method: 'handleCreateEntities',
|
|
370
|
-
rateLimitStatus: this.memoryRateLimiter.getStatus(),
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
try {
|
|
374
|
-
let validatedInput;
|
|
375
|
-
try {
|
|
376
|
-
validatedInput = CreateEntitiesInputSchema.parse(args);
|
|
377
|
-
}
|
|
378
|
-
catch (error) {
|
|
379
|
-
if (error instanceof z.ZodError) {
|
|
380
|
-
throw new ValidationError(formatValidationError(error), {
|
|
381
|
-
component: 'ToolHandlers',
|
|
382
|
-
method: 'handleCreateEntities',
|
|
383
|
-
schema: 'CreateEntitiesInputSchema',
|
|
384
|
-
providedArgs: args,
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
throw error;
|
|
388
|
-
}
|
|
389
|
-
const result = await createEntitiesTool.handler(validatedInput, this.knowledgeGraph);
|
|
390
|
-
let text = 'Knowledge Graph Entity Creation\n';
|
|
391
|
-
text += '='.repeat(60) + '\n\n';
|
|
392
|
-
if (result.count === 0) {
|
|
393
|
-
text += 'No entities were created.\n\n';
|
|
394
|
-
if (result.errors && result.errors.length > 0) {
|
|
395
|
-
text += 'Errors encountered:\n';
|
|
396
|
-
result.errors.forEach(error => {
|
|
397
|
-
text += ` - ${error.name}: ${error.error}\n`;
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
text += `Successfully created ${result.count} ${result.count === 1 ? 'entity' : 'entities'}:\n\n`;
|
|
403
|
-
result.created.forEach((name, index) => {
|
|
404
|
-
text += `${index + 1}. ${name}\n`;
|
|
405
|
-
});
|
|
406
|
-
if (result.errors && result.errors.length > 0) {
|
|
407
|
-
text += '\nSome entities failed:\n';
|
|
408
|
-
result.errors.forEach(error => {
|
|
409
|
-
text += ` - ${error.name}: ${error.error}\n`;
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
text += '\n' + '='.repeat(60) + '\n';
|
|
414
|
-
return {
|
|
415
|
-
content: [
|
|
416
|
-
{
|
|
417
|
-
type: 'text',
|
|
418
|
-
text,
|
|
419
|
-
},
|
|
420
|
-
],
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
catch (error) {
|
|
424
|
-
logError(error, {
|
|
425
|
-
component: 'ToolHandlers',
|
|
426
|
-
method: 'handleCreateEntities',
|
|
427
|
-
operation: 'creating knowledge graph entities',
|
|
428
|
-
data: { entityCount: args?.entities?.length ?? 0 },
|
|
429
|
-
});
|
|
430
|
-
const handled = handleError(error, {
|
|
431
|
-
component: 'ToolHandlers',
|
|
432
|
-
method: 'handleCreateEntities',
|
|
433
|
-
});
|
|
434
|
-
return {
|
|
435
|
-
content: [
|
|
436
|
-
{
|
|
437
|
-
type: 'text',
|
|
438
|
-
text: `Failed to create entities: ${handled.message}`,
|
|
439
|
-
},
|
|
440
|
-
],
|
|
441
|
-
};
|
|
442
|
-
}
|
|
26
|
+
return this.memoryHandler.handleCreateEntities(args);
|
|
443
27
|
}
|
|
444
28
|
async handleBuddyRecordMistake(args) {
|
|
445
|
-
|
|
446
|
-
return this.cloudOnlyModeError('buddy-record-mistake');
|
|
447
|
-
}
|
|
448
|
-
if (!this.memoryRateLimiter.consume()) {
|
|
449
|
-
throw new OperationError('Memory operation rate limit exceeded. Please try again later.', {
|
|
450
|
-
component: 'ToolHandlers',
|
|
451
|
-
method: 'handleBuddyRecordMistake',
|
|
452
|
-
rateLimitStatus: this.memoryRateLimiter.getStatus(),
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
if (!args || typeof args !== 'object') {
|
|
456
|
-
throw new ValidationError('Invalid input: expected object', {
|
|
457
|
-
component: 'ToolHandlers',
|
|
458
|
-
method: 'handleBuddyRecordMistake',
|
|
459
|
-
providedArgs: args,
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
const input = args;
|
|
463
|
-
const requiredFields = ['action', 'errorType', 'userCorrection', 'correctMethod', 'impact', 'preventionMethod'];
|
|
464
|
-
for (const field of requiredFields) {
|
|
465
|
-
if (!(field in input) || !input[field]) {
|
|
466
|
-
throw new ValidationError(`Missing required field: ${field}`, {
|
|
467
|
-
component: 'ToolHandlers',
|
|
468
|
-
method: 'handleBuddyRecordMistake',
|
|
469
|
-
missingField: field,
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return handleBuddyRecordMistake(input, this.unifiedMemoryStore, this.mistakePatternEngine, this.userPreferenceEngine);
|
|
29
|
+
return this.memoryHandler.handleBuddyRecordMistake(args);
|
|
474
30
|
}
|
|
475
31
|
async handleAddObservations(args) {
|
|
476
|
-
|
|
477
|
-
return this.cloudOnlyModeError('add-observations');
|
|
478
|
-
}
|
|
479
|
-
if (!this.memoryRateLimiter.consume()) {
|
|
480
|
-
throw new OperationError('Memory operation rate limit exceeded. Please try again later.', {
|
|
481
|
-
component: 'ToolHandlers',
|
|
482
|
-
method: 'handleAddObservations',
|
|
483
|
-
rateLimitStatus: this.memoryRateLimiter.getStatus(),
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
try {
|
|
487
|
-
let validatedInput;
|
|
488
|
-
try {
|
|
489
|
-
validatedInput = AddObservationsInputSchema.parse(args);
|
|
490
|
-
}
|
|
491
|
-
catch (error) {
|
|
492
|
-
if (error instanceof z.ZodError) {
|
|
493
|
-
throw new ValidationError(formatValidationError(error), {
|
|
494
|
-
component: 'ToolHandlers',
|
|
495
|
-
method: 'handleAddObservations',
|
|
496
|
-
schema: 'AddObservationsInputSchema',
|
|
497
|
-
providedArgs: args,
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
throw error;
|
|
501
|
-
}
|
|
502
|
-
const result = await addObservationsTool.handler(validatedInput, this.knowledgeGraph);
|
|
503
|
-
let text = 'Knowledge Graph Observation Update\n';
|
|
504
|
-
text += '='.repeat(60) + '\n\n';
|
|
505
|
-
if (result.count === 0) {
|
|
506
|
-
text += 'No observations were added.\n\n';
|
|
507
|
-
if (result.notFound && result.notFound.length > 0) {
|
|
508
|
-
text += 'Entities not found:\n';
|
|
509
|
-
result.notFound.forEach(name => {
|
|
510
|
-
text += ` - ${name}\n`;
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
if (result.errors && result.errors.length > 0) {
|
|
514
|
-
text += '\nErrors encountered:\n';
|
|
515
|
-
result.errors.forEach(error => {
|
|
516
|
-
text += ` - ${error.entityName}: ${error.error}\n`;
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
text += `Successfully updated ${result.count} ${result.count === 1 ? 'entity' : 'entities'}:\n\n`;
|
|
522
|
-
result.updated.forEach((name, index) => {
|
|
523
|
-
text += `${index + 1}. ${name}\n`;
|
|
524
|
-
});
|
|
525
|
-
if (result.notFound && result.notFound.length > 0) {
|
|
526
|
-
text += '\nSome entities were not found:\n';
|
|
527
|
-
result.notFound.forEach(name => {
|
|
528
|
-
text += ` - ${name}\n`;
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
if (result.errors && result.errors.length > 0) {
|
|
532
|
-
text += '\nSome updates failed:\n';
|
|
533
|
-
result.errors.forEach(error => {
|
|
534
|
-
text += ` - ${error.entityName}: ${error.error}\n`;
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
text += '\n' + '='.repeat(60) + '\n';
|
|
539
|
-
return {
|
|
540
|
-
content: [
|
|
541
|
-
{
|
|
542
|
-
type: 'text',
|
|
543
|
-
text,
|
|
544
|
-
},
|
|
545
|
-
],
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
catch (error) {
|
|
549
|
-
logError(error, {
|
|
550
|
-
component: 'ToolHandlers',
|
|
551
|
-
method: 'handleAddObservations',
|
|
552
|
-
operation: 'adding observations to entities',
|
|
553
|
-
data: { observationCount: args?.observations?.length ?? 0 },
|
|
554
|
-
});
|
|
555
|
-
const handled = handleError(error, {
|
|
556
|
-
component: 'ToolHandlers',
|
|
557
|
-
method: 'handleAddObservations',
|
|
558
|
-
});
|
|
559
|
-
return {
|
|
560
|
-
content: [
|
|
561
|
-
{
|
|
562
|
-
type: 'text',
|
|
563
|
-
text: `Failed to add observations: ${handled.message}`,
|
|
564
|
-
},
|
|
565
|
-
],
|
|
566
|
-
};
|
|
567
|
-
}
|
|
32
|
+
return this.memoryHandler.handleAddObservations(args);
|
|
568
33
|
}
|
|
569
34
|
async handleCreateRelations(args) {
|
|
570
|
-
|
|
571
|
-
return this.cloudOnlyModeError('create-relations');
|
|
572
|
-
}
|
|
573
|
-
if (!this.memoryRateLimiter.consume()) {
|
|
574
|
-
throw new OperationError('Memory operation rate limit exceeded. Please try again later.', {
|
|
575
|
-
component: 'ToolHandlers',
|
|
576
|
-
method: 'handleCreateRelations',
|
|
577
|
-
rateLimitStatus: this.memoryRateLimiter.getStatus(),
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
try {
|
|
581
|
-
let validatedInput;
|
|
582
|
-
try {
|
|
583
|
-
validatedInput = CreateRelationsInputSchema.parse(args);
|
|
584
|
-
}
|
|
585
|
-
catch (error) {
|
|
586
|
-
if (error instanceof z.ZodError) {
|
|
587
|
-
throw new ValidationError(formatValidationError(error), {
|
|
588
|
-
component: 'ToolHandlers',
|
|
589
|
-
method: 'handleCreateRelations',
|
|
590
|
-
schema: 'CreateRelationsInputSchema',
|
|
591
|
-
providedArgs: args,
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
throw error;
|
|
595
|
-
}
|
|
596
|
-
const result = await createRelationsTool.handler(validatedInput, this.knowledgeGraph);
|
|
597
|
-
let text = 'Knowledge Graph Relation Creation\n';
|
|
598
|
-
text += '='.repeat(60) + '\n\n';
|
|
599
|
-
if (result.count === 0) {
|
|
600
|
-
text += 'No relations were created.\n\n';
|
|
601
|
-
if (result.missingEntities && result.missingEntities.length > 0) {
|
|
602
|
-
text += 'Entities not found:\n';
|
|
603
|
-
result.missingEntities.forEach(name => {
|
|
604
|
-
text += ` - ${name}\n`;
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
if (result.errors && result.errors.length > 0) {
|
|
608
|
-
text += '\nErrors encountered:\n';
|
|
609
|
-
result.errors.forEach(error => {
|
|
610
|
-
text += ` - ${error.from} -> ${error.to}: ${error.error}\n`;
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
else {
|
|
615
|
-
text += `Successfully created ${result.count} ${result.count === 1 ? 'relation' : 'relations'}:\n\n`;
|
|
616
|
-
result.created.forEach((rel, index) => {
|
|
617
|
-
text += `${index + 1}. ${rel.from} --[${rel.type}]--> ${rel.to}\n`;
|
|
618
|
-
});
|
|
619
|
-
if (result.missingEntities && result.missingEntities.length > 0) {
|
|
620
|
-
text += '\nSome entities were not found:\n';
|
|
621
|
-
result.missingEntities.forEach(name => {
|
|
622
|
-
text += ` - ${name}\n`;
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
if (result.errors && result.errors.length > 0) {
|
|
626
|
-
text += '\nSome relations failed:\n';
|
|
627
|
-
result.errors.forEach(error => {
|
|
628
|
-
text += ` - ${error.from} -> ${error.to}: ${error.error}\n`;
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
text += '\n' + '='.repeat(60) + '\n';
|
|
633
|
-
return {
|
|
634
|
-
content: [
|
|
635
|
-
{
|
|
636
|
-
type: 'text',
|
|
637
|
-
text,
|
|
638
|
-
},
|
|
639
|
-
],
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
catch (error) {
|
|
643
|
-
logError(error, {
|
|
644
|
-
component: 'ToolHandlers',
|
|
645
|
-
method: 'handleCreateRelations',
|
|
646
|
-
operation: 'creating entity relations',
|
|
647
|
-
data: { relationCount: args?.relations?.length ?? 0 },
|
|
648
|
-
});
|
|
649
|
-
const handled = handleError(error, {
|
|
650
|
-
component: 'ToolHandlers',
|
|
651
|
-
method: 'handleCreateRelations',
|
|
652
|
-
});
|
|
653
|
-
return {
|
|
654
|
-
content: [
|
|
655
|
-
{
|
|
656
|
-
type: 'text',
|
|
657
|
-
text: `Failed to create relations: ${handled.message}`,
|
|
658
|
-
},
|
|
659
|
-
],
|
|
660
|
-
};
|
|
661
|
-
}
|
|
35
|
+
return this.memoryHandler.handleCreateRelations(args);
|
|
662
36
|
}
|
|
663
37
|
async handleGenerateTests(args) {
|
|
664
|
-
|
|
665
|
-
const validatedInput = GenerateTestsInputSchema.parse(args);
|
|
666
|
-
const input = validatedInput;
|
|
667
|
-
const result = await generateTestsTool(input, this.samplingClient);
|
|
668
|
-
let text = 'Test Generation Result\n';
|
|
669
|
-
text += '='.repeat(60) + '\n\n';
|
|
670
|
-
text += `${result.message}\n\n`;
|
|
671
|
-
text += '```typescript\n';
|
|
672
|
-
text += result.testCode;
|
|
673
|
-
text += '\n```\n\n';
|
|
674
|
-
text += '='.repeat(60) + '\n';
|
|
675
|
-
text += '\nNext Steps:\n';
|
|
676
|
-
text += ' - Review the generated tests for accuracy\n';
|
|
677
|
-
text += ' - Adjust test cases as needed\n';
|
|
678
|
-
text += ' - Add edge cases if necessary\n';
|
|
679
|
-
text += ' - Run tests to verify they pass\n';
|
|
680
|
-
return {
|
|
681
|
-
content: [
|
|
682
|
-
{
|
|
683
|
-
type: 'text',
|
|
684
|
-
text,
|
|
685
|
-
},
|
|
686
|
-
],
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
catch (error) {
|
|
690
|
-
logError(error, {
|
|
691
|
-
component: 'ToolHandlers',
|
|
692
|
-
method: 'handleGenerateTests',
|
|
693
|
-
operation: 'generating tests',
|
|
694
|
-
data: { args },
|
|
695
|
-
});
|
|
696
|
-
const handled = handleError(error, {
|
|
697
|
-
component: 'ToolHandlers',
|
|
698
|
-
method: 'handleGenerateTests',
|
|
699
|
-
});
|
|
700
|
-
return {
|
|
701
|
-
content: [
|
|
702
|
-
{
|
|
703
|
-
type: 'text',
|
|
704
|
-
text: `Failed to generate tests: ${handled.message}`,
|
|
705
|
-
},
|
|
706
|
-
],
|
|
707
|
-
};
|
|
708
|
-
}
|
|
38
|
+
return this.systemHandler.handleGenerateTests(args);
|
|
709
39
|
}
|
|
710
40
|
}
|
|
711
41
|
//# sourceMappingURL=ToolHandlers.js.map
|