@hailer/mcp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/tool-builder.md +37 -0
- package/.claude/commands/ws-pull.md +44 -0
- package/.claude/settings.json +8 -0
- package/.claude/settings.local.json +49 -0
- package/.claude/skills/activity-api/SKILL.md +96 -0
- package/.claude/skills/activity-api/references/activity-endpoints.md +845 -0
- package/.claude/skills/add-app-member-skill/SKILL.md +977 -0
- package/.claude/skills/agent-building/SKILL.md +243 -0
- package/.claude/skills/agent-building/references/architecture-patterns.md +446 -0
- package/.claude/skills/agent-building/references/code-examples.md +587 -0
- package/.claude/skills/agent-building/references/implementation-guide.md +619 -0
- package/.claude/skills/app-api/SKILL.md +219 -0
- package/.claude/skills/app-api/references/app-endpoints.md +759 -0
- package/.claude/skills/building-hailer-apps-skill/SKILL.md +548 -0
- package/.claude/skills/create-app-skill/SKILL.md +1101 -0
- package/.claude/skills/create-insight-skill/SKILL.md +1317 -0
- package/.claude/skills/get-insight-data-skill/SKILL.md +1053 -0
- package/.claude/skills/hailer-api/SKILL.md +283 -0
- package/.claude/skills/hailer-api/references/activities.md +620 -0
- package/.claude/skills/hailer-api/references/authentication.md +216 -0
- package/.claude/skills/hailer-api/references/datasets.md +437 -0
- package/.claude/skills/hailer-api/references/files.md +301 -0
- package/.claude/skills/hailer-api/references/insights.md +469 -0
- package/.claude/skills/hailer-api/references/workflows.md +720 -0
- package/.claude/skills/hailer-api/references/workspaces-users.md +445 -0
- package/.claude/skills/insight-api/SKILL.md +185 -0
- package/.claude/skills/insight-api/references/insight-endpoints.md +514 -0
- package/.claude/skills/install-workflow-skill/SKILL.md +1056 -0
- package/.claude/skills/list-apps-skill/SKILL.md +1010 -0
- package/.claude/skills/list-workflows-minimal-skill/SKILL.md +992 -0
- package/.claude/skills/local-first-skill/SKILL.md +570 -0
- package/.claude/skills/mcp-tools/SKILL.md +419 -0
- package/.claude/skills/mcp-tools/references/api-endpoints.md +499 -0
- package/.claude/skills/mcp-tools/references/data-structures.md +554 -0
- package/.claude/skills/mcp-tools/references/implementation-patterns.md +717 -0
- package/.claude/skills/preview-insight-skill/SKILL.md +1290 -0
- package/.claude/skills/publish-hailer-app-skill/SKILL.md +453 -0
- package/.claude/skills/remove-app-member-skill/SKILL.md +671 -0
- package/.claude/skills/remove-app-skill/SKILL.md +985 -0
- package/.claude/skills/remove-insight-skill/SKILL.md +1011 -0
- package/.claude/skills/remove-workflow-skill/SKILL.md +920 -0
- package/.claude/skills/scaffold-hailer-app-skill/SKILL.md +1034 -0
- package/.claude/skills/skill-testing/README.md +137 -0
- package/.claude/skills/skill-testing/SKILL.md +348 -0
- package/.claude/skills/skill-testing/references/test-patterns.md +705 -0
- package/.claude/skills/skill-testing/references/testing-guide.md +603 -0
- package/.claude/skills/skill-testing/references/validation-checklist.md +537 -0
- package/.claude/skills/tool-builder/SKILL.md +328 -0
- package/.claude/skills/update-app-skill/SKILL.md +970 -0
- package/.claude/skills/update-workflow-field-skill/SKILL.md +1098 -0
- package/.env.example +81 -0
- package/.mcp.json +13 -0
- package/README.md +297 -0
- package/dist/app.d.ts +4 -0
- package/dist/app.js +74 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +5 -0
- package/dist/client/adaptive-documentation-bot.d.ts +108 -0
- package/dist/client/adaptive-documentation-bot.js +475 -0
- package/dist/client/adaptive-documentation-types.d.ts +66 -0
- package/dist/client/adaptive-documentation-types.js +9 -0
- package/dist/client/agent-activity-bot.d.ts +51 -0
- package/dist/client/agent-activity-bot.js +166 -0
- package/dist/client/agent-tracker.d.ts +499 -0
- package/dist/client/agent-tracker.js +659 -0
- package/dist/client/description-updater.d.ts +56 -0
- package/dist/client/description-updater.js +259 -0
- package/dist/client/log-parser.d.ts +72 -0
- package/dist/client/log-parser.js +387 -0
- package/dist/client/mcp-client.d.ts +50 -0
- package/dist/client/mcp-client.js +532 -0
- package/dist/client/message-processor.d.ts +35 -0
- package/dist/client/message-processor.js +352 -0
- package/dist/client/multi-bot-manager.d.ts +24 -0
- package/dist/client/multi-bot-manager.js +74 -0
- package/dist/client/providers/anthropic-provider.d.ts +19 -0
- package/dist/client/providers/anthropic-provider.js +631 -0
- package/dist/client/providers/llm-provider.d.ts +47 -0
- package/dist/client/providers/llm-provider.js +367 -0
- package/dist/client/providers/openai-provider.d.ts +23 -0
- package/dist/client/providers/openai-provider.js +621 -0
- package/dist/client/simple-llm-caller.d.ts +19 -0
- package/dist/client/simple-llm-caller.js +100 -0
- package/dist/client/skill-generator.d.ts +81 -0
- package/dist/client/skill-generator.js +386 -0
- package/dist/client/test-adaptive-bot.d.ts +9 -0
- package/dist/client/test-adaptive-bot.js +82 -0
- package/dist/client/token-pricing.d.ts +38 -0
- package/dist/client/token-pricing.js +127 -0
- package/dist/client/token-tracker.d.ts +232 -0
- package/dist/client/token-tracker.js +457 -0
- package/dist/client/token-usage-bot.d.ts +53 -0
- package/dist/client/token-usage-bot.js +153 -0
- package/dist/client/tool-executor.d.ts +69 -0
- package/dist/client/tool-executor.js +159 -0
- package/dist/client/tool-schema-loader.d.ts +60 -0
- package/dist/client/tool-schema-loader.js +178 -0
- package/dist/client/types.d.ts +69 -0
- package/dist/client/types.js +7 -0
- package/dist/config.d.ts +162 -0
- package/dist/config.js +296 -0
- package/dist/core.d.ts +26 -0
- package/dist/core.js +147 -0
- package/dist/lib/context-manager.d.ts +111 -0
- package/dist/lib/context-manager.js +431 -0
- package/dist/lib/logger.d.ts +74 -0
- package/dist/lib/logger.js +277 -0
- package/dist/lib/materialize.d.ts +3 -0
- package/dist/lib/materialize.js +101 -0
- package/dist/lib/normalizedName.d.ts +7 -0
- package/dist/lib/normalizedName.js +48 -0
- package/dist/lib/prompt-length-manager.d.ts +81 -0
- package/dist/lib/prompt-length-manager.js +457 -0
- package/dist/lib/terminal-prompt.d.ts +9 -0
- package/dist/lib/terminal-prompt.js +108 -0
- package/dist/mcp/UserContextCache.d.ts +56 -0
- package/dist/mcp/UserContextCache.js +163 -0
- package/dist/mcp/auth.d.ts +2 -0
- package/dist/mcp/auth.js +29 -0
- package/dist/mcp/hailer-clients.d.ts +42 -0
- package/dist/mcp/hailer-clients.js +246 -0
- package/dist/mcp/signal-handler.d.ts +45 -0
- package/dist/mcp/signal-handler.js +317 -0
- package/dist/mcp/tool-registry.d.ts +100 -0
- package/dist/mcp/tool-registry.js +306 -0
- package/dist/mcp/tools/activity.d.ts +15 -0
- package/dist/mcp/tools/activity.js +955 -0
- package/dist/mcp/tools/app.d.ts +20 -0
- package/dist/mcp/tools/app.js +1488 -0
- package/dist/mcp/tools/discussion.d.ts +19 -0
- package/dist/mcp/tools/discussion.js +950 -0
- package/dist/mcp/tools/file.d.ts +15 -0
- package/dist/mcp/tools/file.js +119 -0
- package/dist/mcp/tools/insight.d.ts +17 -0
- package/dist/mcp/tools/insight.js +806 -0
- package/dist/mcp/tools/skill.d.ts +10 -0
- package/dist/mcp/tools/skill.js +279 -0
- package/dist/mcp/tools/user.d.ts +10 -0
- package/dist/mcp/tools/user.js +108 -0
- package/dist/mcp/tools/workflow-template.d.ts +19 -0
- package/dist/mcp/tools/workflow-template.js +822 -0
- package/dist/mcp/tools/workflow.d.ts +18 -0
- package/dist/mcp/tools/workflow.js +1362 -0
- package/dist/mcp/utils/api-errors.d.ts +45 -0
- package/dist/mcp/utils/api-errors.js +160 -0
- package/dist/mcp/utils/data-transformers.d.ts +102 -0
- package/dist/mcp/utils/data-transformers.js +194 -0
- package/dist/mcp/utils/file-upload.d.ts +33 -0
- package/dist/mcp/utils/file-upload.js +148 -0
- package/dist/mcp/utils/hailer-api-client.d.ts +120 -0
- package/dist/mcp/utils/hailer-api-client.js +323 -0
- package/dist/mcp/utils/index.d.ts +13 -0
- package/dist/mcp/utils/index.js +39 -0
- package/dist/mcp/utils/logger.d.ts +42 -0
- package/dist/mcp/utils/logger.js +103 -0
- package/dist/mcp/utils/types.d.ts +286 -0
- package/dist/mcp/utils/types.js +7 -0
- package/dist/mcp/workspace-cache.d.ts +42 -0
- package/dist/mcp/workspace-cache.js +97 -0
- package/dist/mcp-server.d.ts +42 -0
- package/dist/mcp-server.js +280 -0
- package/package.json +56 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Adaptive Documentation Bot
|
|
4
|
+
*
|
|
5
|
+
* Monitors MCP logs for tool call errors and automatically improves
|
|
6
|
+
* tool descriptions and skills based on actual LLM usage patterns.
|
|
7
|
+
*
|
|
8
|
+
* Key Features:
|
|
9
|
+
* - Detects when LLMs make mistakes calling tools
|
|
10
|
+
* - Uses LLM to analyze what went wrong
|
|
11
|
+
* - Automatically updates tool descriptions
|
|
12
|
+
* - Creates/updates skill documents with common mistakes
|
|
13
|
+
* - Learns and improves over time
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.AdaptiveDocumentationBot = void 0;
|
|
17
|
+
const logger_1 = require("../lib/logger");
|
|
18
|
+
const log_parser_1 = require("./log-parser");
|
|
19
|
+
const description_updater_1 = require("./description-updater");
|
|
20
|
+
const skill_generator_1 = require("./skill-generator");
|
|
21
|
+
const simple_llm_caller_1 = require("./simple-llm-caller");
|
|
22
|
+
const logger = (0, logger_1.createLogger)({ component: 'AdaptiveDocumentationBot' });
|
|
23
|
+
class AdaptiveDocumentationBot {
|
|
24
|
+
logParser;
|
|
25
|
+
descriptionUpdater;
|
|
26
|
+
skillGenerator;
|
|
27
|
+
llmCaller;
|
|
28
|
+
config;
|
|
29
|
+
errorPatterns = new Map();
|
|
30
|
+
monitoringInterval;
|
|
31
|
+
isMonitoring = false;
|
|
32
|
+
constructor(apiKey, provider = 'anthropic', config = {}) {
|
|
33
|
+
this.llmCaller = new simple_llm_caller_1.SimpleLLMCaller(provider, apiKey);
|
|
34
|
+
this.config = {
|
|
35
|
+
enabled: config.enabled ?? true,
|
|
36
|
+
autoUpdate: config.autoUpdate ?? true,
|
|
37
|
+
updateInterval: config.updateInterval ?? 60000, // 1 minute
|
|
38
|
+
minErrorCount: config.minErrorCount ?? 3,
|
|
39
|
+
skillGeneration: config.skillGeneration ?? true,
|
|
40
|
+
logPath: config.logPath
|
|
41
|
+
};
|
|
42
|
+
this.logParser = new log_parser_1.LogParser(this.config.logPath);
|
|
43
|
+
this.descriptionUpdater = new description_updater_1.DescriptionUpdater();
|
|
44
|
+
this.skillGenerator = new skill_generator_1.SkillGenerator();
|
|
45
|
+
logger.info('Adaptive Documentation Bot initialized', {
|
|
46
|
+
autoUpdate: this.config.autoUpdate,
|
|
47
|
+
updateInterval: this.config.updateInterval,
|
|
48
|
+
minErrorCount: this.config.minErrorCount
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Start monitoring logs for errors
|
|
53
|
+
*/
|
|
54
|
+
startMonitoring() {
|
|
55
|
+
if (this.isMonitoring) {
|
|
56
|
+
logger.warn('Already monitoring logs');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.isMonitoring = true;
|
|
60
|
+
logger.info('🔍 Started monitoring MCP logs for tool call errors');
|
|
61
|
+
// Run immediately
|
|
62
|
+
this.monitorAndImprove().catch(error => {
|
|
63
|
+
logger.error('Error in monitoring loop', error);
|
|
64
|
+
});
|
|
65
|
+
// Then run on interval (as backup)
|
|
66
|
+
this.monitoringInterval = setInterval(() => {
|
|
67
|
+
this.monitorAndImprove().catch(error => {
|
|
68
|
+
logger.error('Error in monitoring loop', error);
|
|
69
|
+
});
|
|
70
|
+
}, this.config.updateInterval);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Analyze logs immediately after a conversation ends
|
|
74
|
+
* Called by MCP Client after each bot conversation
|
|
75
|
+
*/
|
|
76
|
+
async analyzeAfterConversation() {
|
|
77
|
+
if (!this.isMonitoring) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
logger.debug('🔍 Analyzing logs after conversation completion');
|
|
81
|
+
// Wait 500ms for logger to finish writing
|
|
82
|
+
// This prevents race condition where we try to read while logger is mid-write
|
|
83
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
84
|
+
try {
|
|
85
|
+
await this.monitorAndImprove();
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
logger.error('Failed to analyze after conversation', error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Report error directly (not from logs)
|
|
93
|
+
* Use this to capture errors from active conversations
|
|
94
|
+
*/
|
|
95
|
+
reportError(error) {
|
|
96
|
+
if (!this.isMonitoring) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const key = this.getPatternKey(error);
|
|
100
|
+
const existing = this.errorPatterns.get(key);
|
|
101
|
+
if (existing) {
|
|
102
|
+
existing.count++;
|
|
103
|
+
existing.lastSeen = error.timestamp;
|
|
104
|
+
existing.examples.push(error);
|
|
105
|
+
logger.debug('Updated error pattern', {
|
|
106
|
+
pattern: key,
|
|
107
|
+
count: existing.count
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
this.errorPatterns.set(key, {
|
|
112
|
+
pattern: key,
|
|
113
|
+
description: this.generatePatternDescription(error),
|
|
114
|
+
count: 1,
|
|
115
|
+
lastSeen: error.timestamp,
|
|
116
|
+
firstSeen: error.timestamp,
|
|
117
|
+
examples: [error]
|
|
118
|
+
});
|
|
119
|
+
logger.debug('New error pattern detected', {
|
|
120
|
+
pattern: key,
|
|
121
|
+
toolName: error.toolName
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// Check if we should analyze this error immediately
|
|
125
|
+
const pattern = this.errorPatterns.get(key);
|
|
126
|
+
if (pattern && pattern.count >= this.config.minErrorCount && !pattern.suggestedFix) {
|
|
127
|
+
logger.info('Error threshold reached, analyzing immediately', {
|
|
128
|
+
toolName: error.toolName,
|
|
129
|
+
count: pattern.count
|
|
130
|
+
});
|
|
131
|
+
// Analyze asynchronously
|
|
132
|
+
this.analyzeAndImprove(pattern).catch(err => {
|
|
133
|
+
logger.error('Failed to analyze error immediately', err);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Stop monitoring logs
|
|
139
|
+
*/
|
|
140
|
+
stopMonitoring() {
|
|
141
|
+
if (this.monitoringInterval) {
|
|
142
|
+
clearInterval(this.monitoringInterval);
|
|
143
|
+
this.monitoringInterval = undefined;
|
|
144
|
+
}
|
|
145
|
+
this.isMonitoring = false;
|
|
146
|
+
logger.info('Stopped monitoring MCP logs');
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Main monitoring loop: parse errors and apply improvements
|
|
150
|
+
*/
|
|
151
|
+
async monitorAndImprove() {
|
|
152
|
+
try {
|
|
153
|
+
// 1. Parse logs for new errors
|
|
154
|
+
const errors = await this.logParser.parseToolCallErrors();
|
|
155
|
+
if (errors.length === 0) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
logger.info('📊 Detected tool call errors', {
|
|
159
|
+
count: errors.length,
|
|
160
|
+
uniqueTools: new Set(errors.map(e => e.toolName)).size
|
|
161
|
+
});
|
|
162
|
+
// 2. Group errors by tool and pattern
|
|
163
|
+
this.updateErrorPatterns(errors);
|
|
164
|
+
// 3. Analyze and improve tools that meet minimum error threshold
|
|
165
|
+
for (const pattern of this.errorPatterns.values()) {
|
|
166
|
+
if (pattern.count >= this.config.minErrorCount && !pattern.suggestedFix) {
|
|
167
|
+
await this.analyzeAndImprove(pattern);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
logger.error('Failed to monitor and improve', error);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Update error patterns with new errors
|
|
177
|
+
*/
|
|
178
|
+
updateErrorPatterns(errors) {
|
|
179
|
+
for (const error of errors) {
|
|
180
|
+
const key = this.getPatternKey(error);
|
|
181
|
+
const existing = this.errorPatterns.get(key);
|
|
182
|
+
if (existing) {
|
|
183
|
+
existing.count++;
|
|
184
|
+
existing.lastSeen = error.timestamp;
|
|
185
|
+
existing.examples.push(error);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
this.errorPatterns.set(key, {
|
|
189
|
+
pattern: key,
|
|
190
|
+
description: this.generatePatternDescription(error),
|
|
191
|
+
count: 1,
|
|
192
|
+
lastSeen: error.timestamp,
|
|
193
|
+
firstSeen: error.timestamp,
|
|
194
|
+
examples: [error]
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Analyze error pattern and apply improvements
|
|
201
|
+
*/
|
|
202
|
+
async analyzeAndImprove(pattern) {
|
|
203
|
+
try {
|
|
204
|
+
logger.info('🔍 Analyzing error pattern', {
|
|
205
|
+
pattern: pattern.pattern,
|
|
206
|
+
count: pattern.count,
|
|
207
|
+
tool: pattern.examples[0].toolName
|
|
208
|
+
});
|
|
209
|
+
// 1. Analyze with LLM
|
|
210
|
+
const analysis = await this.analyzeWithLLM(pattern);
|
|
211
|
+
if (!analysis.isDescriptionIssue && !analysis.needsSkill) {
|
|
212
|
+
logger.debug('No action needed for this error pattern', {
|
|
213
|
+
pattern: pattern.pattern
|
|
214
|
+
});
|
|
215
|
+
pattern.suggestedFix = 'no-action-needed';
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
// 2. Apply improvements based on analysis
|
|
219
|
+
if (this.config.autoUpdate) {
|
|
220
|
+
await this.applyImprovements(pattern, analysis);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
logger.info('Auto-update disabled, would improve:', {
|
|
224
|
+
tool: pattern.examples[0].toolName,
|
|
225
|
+
analysis
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
// Mark as processed
|
|
229
|
+
pattern.suggestedFix = 'applied';
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
logger.error('Failed to analyze and improve pattern', error, {
|
|
233
|
+
pattern: pattern.pattern
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Analyze error pattern using LLM
|
|
239
|
+
*/
|
|
240
|
+
async analyzeWithLLM(pattern) {
|
|
241
|
+
const example = pattern.examples[0];
|
|
242
|
+
const prompt = `You are analyzing MCP tool call errors to improve tool descriptions for an internal chat bot.
|
|
243
|
+
|
|
244
|
+
**IMPORTANT CONTEXT**: This chat bot CANNOT use skills (it only has READ + WRITE tools, no get_skill capability).
|
|
245
|
+
All improvements must be in the tool description itself, not in external skill documents.
|
|
246
|
+
|
|
247
|
+
**Tool**: ${example.toolName}
|
|
248
|
+
**Error Message**: ${example.errorMessage}
|
|
249
|
+
**Error Count**: ${pattern.count} times
|
|
250
|
+
**Example Attempted Call**:
|
|
251
|
+
\`\`\`json
|
|
252
|
+
${JSON.stringify(example.attemptedCall, null, 2)}
|
|
253
|
+
\`\`\`
|
|
254
|
+
|
|
255
|
+
Analyze this error and respond in JSON format:
|
|
256
|
+
{
|
|
257
|
+
"isDescriptionIssue": boolean (true if the tool description is unclear - ALWAYS true since bot can't use skills),
|
|
258
|
+
"needsSkill": boolean (ALWAYS false - bot cannot access skills, only external Claude Code users can),
|
|
259
|
+
"problem": "string (what was misunderstood in the current description)",
|
|
260
|
+
"suggestion": "string (how to improve the description INLINE with examples and clear requirements)",
|
|
261
|
+
"priority": "low" | "medium" | "high" | "critical",
|
|
262
|
+
"affectedParameter": "string (if specific parameter caused issue)",
|
|
263
|
+
"incorrectUsage": {...} (the wrong way LLM used it),
|
|
264
|
+
"correctUsage": {...} (the correct way to use it)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
Focus on:
|
|
268
|
+
1. What did the LLM misunderstand from the current description?
|
|
269
|
+
2. Which required parameters are not clearly marked as REQUIRED?
|
|
270
|
+
3. What format requirements are missing or unclear?
|
|
271
|
+
4. Add inline examples directly in the description (NOT in skills)
|
|
272
|
+
5. Use ⚠️ REQUIRED or ✅ EXAMPLE markers in the description
|
|
273
|
+
|
|
274
|
+
Return ONLY valid JSON, no other text.`;
|
|
275
|
+
try {
|
|
276
|
+
const response = await this.llmCaller.generate(prompt, 'You are a technical documentation expert. Analyze errors and suggest improvements.');
|
|
277
|
+
// Extract JSON from response
|
|
278
|
+
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
279
|
+
if (!jsonMatch) {
|
|
280
|
+
throw new Error('LLM response did not contain JSON');
|
|
281
|
+
}
|
|
282
|
+
const analysis = JSON.parse(jsonMatch[0]);
|
|
283
|
+
logger.debug('LLM analysis complete', { analysis });
|
|
284
|
+
return analysis;
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
logger.error('Failed to analyze with LLM', error);
|
|
288
|
+
// Return conservative default
|
|
289
|
+
return {
|
|
290
|
+
isDescriptionIssue: true,
|
|
291
|
+
needsSkill: pattern.count >= 5,
|
|
292
|
+
problem: 'Analysis failed - assuming description issue',
|
|
293
|
+
suggestion: 'Add clearer examples and emphasize critical requirements',
|
|
294
|
+
priority: 'medium'
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Apply improvements based on analysis
|
|
300
|
+
*/
|
|
301
|
+
async applyImprovements(pattern, analysis) {
|
|
302
|
+
const toolName = pattern.examples[0].toolName;
|
|
303
|
+
// 1. Update description if needed
|
|
304
|
+
if (analysis.isDescriptionIssue) {
|
|
305
|
+
const improved = await this.generateImprovedDescription(toolName, pattern, analysis);
|
|
306
|
+
if (improved) {
|
|
307
|
+
await this.descriptionUpdater.updateToolDescription(toolName, improved, analysis.problem, pattern.examples[0]);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// 2. Update parameter description if specific parameter issue
|
|
311
|
+
if (analysis.affectedParameter) {
|
|
312
|
+
const paramImproved = await this.generateImprovedParameterDescription(toolName, analysis.affectedParameter, analysis);
|
|
313
|
+
if (paramImproved) {
|
|
314
|
+
await this.descriptionUpdater.updateParameterDescription(toolName, analysis.affectedParameter, paramImproved, analysis.problem);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// 3. Create/update skill if needed
|
|
318
|
+
if (this.config.skillGeneration && analysis.needsSkill) {
|
|
319
|
+
await this.skillGenerator.updateOrCreateSkill(toolName, pattern, analysis.incorrectUsage || pattern.examples[0].attemptedCall, analysis.correctUsage || {});
|
|
320
|
+
// Update skill summary
|
|
321
|
+
await this.skillGenerator.updateSkillSummary(toolName);
|
|
322
|
+
}
|
|
323
|
+
logger.info('✅ Improvements applied', {
|
|
324
|
+
tool: toolName,
|
|
325
|
+
descriptionUpdated: analysis.isDescriptionIssue,
|
|
326
|
+
parameterUpdated: !!analysis.affectedParameter,
|
|
327
|
+
skillUpdated: analysis.needsSkill && this.config.skillGeneration
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Generate improved description using LLM
|
|
332
|
+
*/
|
|
333
|
+
async generateImprovedDescription(toolName, pattern, analysis) {
|
|
334
|
+
// Get current description (would need to read from tool files)
|
|
335
|
+
// For now, generate based on analysis
|
|
336
|
+
const prompt = `Generate an improved tool description for "${toolName}" for a chat bot that CANNOT load external skills.
|
|
337
|
+
|
|
338
|
+
**Problem**: ${analysis.problem}
|
|
339
|
+
**Suggestion**: ${analysis.suggestion}
|
|
340
|
+
**Error Count**: ${pattern.count} times
|
|
341
|
+
**Incorrect Usage (what the bot did WRONG)**: ${JSON.stringify(analysis.incorrectUsage)}
|
|
342
|
+
**Correct Usage (what it SHOULD do)**: ${JSON.stringify(analysis.correctUsage)}
|
|
343
|
+
|
|
344
|
+
CRITICAL Requirements:
|
|
345
|
+
1. Show BOTH the wrong and right way - use ✅ CORRECT: and ❌ WRONG: labels
|
|
346
|
+
2. Include the ACTUAL incorrect JSON that was attempted
|
|
347
|
+
3. Be EXTREMELY explicit about parameter types (string vs array, required vs optional)
|
|
348
|
+
4. Use ⚠️ CRITICAL: for the most important requirement
|
|
349
|
+
5. Keep description under 400 characters for readability
|
|
350
|
+
|
|
351
|
+
Example format that SHOWS the contrast:
|
|
352
|
+
"📋 [Brief description]. ⚠️ CRITICAL: workflowId must be STRING (NOT array!), phaseId is REQUIRED. ✅ CORRECT: {"workflowId": "abc123", "phaseId": "xyz"} ❌ WRONG: {"workflowId": ["abc123"]} (causes validation error)"
|
|
353
|
+
|
|
354
|
+
Return ONLY the improved description text, no JSON or extra formatting.`;
|
|
355
|
+
try {
|
|
356
|
+
const improved = await this.llmCaller.generate(prompt, 'You are a technical writer. Write clear, concise tool descriptions.');
|
|
357
|
+
return improved.trim();
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
logger.error('Failed to generate improved description', error);
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Generate improved parameter description using LLM
|
|
366
|
+
*/
|
|
367
|
+
async generateImprovedParameterDescription(toolName, parameterName, analysis) {
|
|
368
|
+
const prompt = `Generate an improved parameter description for "${parameterName}" in tool "${toolName}".
|
|
369
|
+
|
|
370
|
+
**Problem**: ${analysis.problem}
|
|
371
|
+
**Incorrect Usage**:
|
|
372
|
+
\`\`\`json
|
|
373
|
+
${JSON.stringify(analysis.incorrectUsage, null, 2)}
|
|
374
|
+
\`\`\`
|
|
375
|
+
|
|
376
|
+
**Correct Usage**:
|
|
377
|
+
\`\`\`json
|
|
378
|
+
${JSON.stringify(analysis.correctUsage, null, 2)}
|
|
379
|
+
\`\`\`
|
|
380
|
+
|
|
381
|
+
Requirements:
|
|
382
|
+
- Be specific about format/type requirements
|
|
383
|
+
- Use ⚠️ CRITICAL or ✅ CORRECT for emphasis
|
|
384
|
+
- Include example format if helpful
|
|
385
|
+
- Keep it under 100 words
|
|
386
|
+
|
|
387
|
+
Return ONLY the improved description text.`;
|
|
388
|
+
try {
|
|
389
|
+
const improved = await this.llmCaller.generate(prompt, 'You are a technical writer. Write clear parameter descriptions.');
|
|
390
|
+
return improved.trim();
|
|
391
|
+
}
|
|
392
|
+
catch (error) {
|
|
393
|
+
logger.error('Failed to generate improved parameter description', error);
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Generate pattern key for grouping similar errors
|
|
399
|
+
*/
|
|
400
|
+
getPatternKey(error) {
|
|
401
|
+
// Group by tool name and error message pattern
|
|
402
|
+
return `${error.toolName}:${error.errorMessage}`;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Generate human-readable description for error pattern
|
|
406
|
+
*/
|
|
407
|
+
generatePatternDescription(error) {
|
|
408
|
+
const message = error.errorMessage.toLowerCase();
|
|
409
|
+
if (message.includes('required') || message.includes('missing')) {
|
|
410
|
+
return 'Missing required parameter';
|
|
411
|
+
}
|
|
412
|
+
else if (message.includes('validation') || message.includes('invalid')) {
|
|
413
|
+
return 'Parameter validation failed';
|
|
414
|
+
}
|
|
415
|
+
else if (message.includes('format') || message.includes('type')) {
|
|
416
|
+
return 'Incorrect parameter format';
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
return 'Tool call error';
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Get statistics about adaptive bot performance
|
|
424
|
+
*/
|
|
425
|
+
getStats() {
|
|
426
|
+
return {
|
|
427
|
+
monitoring: this.isMonitoring,
|
|
428
|
+
errorPatterns: this.errorPatterns.size,
|
|
429
|
+
improvements: this.descriptionUpdater.getStats(),
|
|
430
|
+
skills: this.skillGenerator.getStats()
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get error patterns for a specific tool
|
|
435
|
+
*/
|
|
436
|
+
getToolErrorPatterns(toolName) {
|
|
437
|
+
const patterns = [];
|
|
438
|
+
for (const pattern of this.errorPatterns.values()) {
|
|
439
|
+
if (pattern.examples[0].toolName === toolName) {
|
|
440
|
+
patterns.push(pattern);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return patterns;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Test mode - parse errors and show what would be improved (without applying changes)
|
|
447
|
+
*/
|
|
448
|
+
async testRun() {
|
|
449
|
+
const errors = await this.logParser.parseToolCallErrors();
|
|
450
|
+
this.updateErrorPatterns(errors);
|
|
451
|
+
const suggestions = [];
|
|
452
|
+
for (const pattern of this.errorPatterns.values()) {
|
|
453
|
+
if (pattern.count >= this.config.minErrorCount && !pattern.suggestedFix) {
|
|
454
|
+
const toolName = pattern.examples[0].toolName;
|
|
455
|
+
// Check if existing skill exists
|
|
456
|
+
const existingSkill = await this.skillGenerator['findExistingSkill'](toolName);
|
|
457
|
+
suggestions.push({
|
|
458
|
+
toolName,
|
|
459
|
+
errorCount: pattern.count,
|
|
460
|
+
errorMessage: pattern.examples[0].errorMessage,
|
|
461
|
+
existingSkill: existingSkill?.name,
|
|
462
|
+
wouldCreateSkill: !existingSkill,
|
|
463
|
+
wouldUpdateSkill: !!existingSkill
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return {
|
|
468
|
+
errors,
|
|
469
|
+
patterns: Array.from(this.errorPatterns.values()),
|
|
470
|
+
suggestions
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
exports.AdaptiveDocumentationBot = AdaptiveDocumentationBot;
|
|
475
|
+
//# sourceMappingURL=adaptive-documentation-bot.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for Adaptive Documentation Bot
|
|
3
|
+
*
|
|
4
|
+
* Monitors MCP logs and automatically improves tool descriptions and skills
|
|
5
|
+
* based on actual LLM usage errors.
|
|
6
|
+
*/
|
|
7
|
+
export interface ToolCallError {
|
|
8
|
+
timestamp: number;
|
|
9
|
+
toolName: string;
|
|
10
|
+
errorMessage: string;
|
|
11
|
+
attemptedCall: any;
|
|
12
|
+
actualParameters?: any;
|
|
13
|
+
context?: {
|
|
14
|
+
conversationId?: string;
|
|
15
|
+
userId?: string;
|
|
16
|
+
provider?: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface ErrorPattern {
|
|
21
|
+
pattern: string;
|
|
22
|
+
description: string;
|
|
23
|
+
count: number;
|
|
24
|
+
lastSeen: number;
|
|
25
|
+
firstSeen: number;
|
|
26
|
+
examples: ToolCallError[];
|
|
27
|
+
rootCause?: string;
|
|
28
|
+
suggestedFix?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ErrorAnalysis {
|
|
31
|
+
isDescriptionIssue: boolean;
|
|
32
|
+
needsSkill: boolean;
|
|
33
|
+
problem: string;
|
|
34
|
+
suggestion: string;
|
|
35
|
+
priority: 'low' | 'medium' | 'high' | 'critical';
|
|
36
|
+
affectedParameter?: string;
|
|
37
|
+
incorrectUsage?: any;
|
|
38
|
+
correctUsage?: any;
|
|
39
|
+
}
|
|
40
|
+
export interface Improvement {
|
|
41
|
+
timestamp: number;
|
|
42
|
+
toolName: string;
|
|
43
|
+
type: 'description' | 'schema' | 'skill';
|
|
44
|
+
oldValue: string;
|
|
45
|
+
newValue: string;
|
|
46
|
+
triggeredBy: ToolCallError;
|
|
47
|
+
reason: string;
|
|
48
|
+
applied: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface SkillMistake {
|
|
51
|
+
title: string;
|
|
52
|
+
frequency: number;
|
|
53
|
+
lastSeen: number;
|
|
54
|
+
wrongExample: any;
|
|
55
|
+
correctExample: any;
|
|
56
|
+
explanation: string;
|
|
57
|
+
}
|
|
58
|
+
export interface AdaptiveBotConfig {
|
|
59
|
+
enabled: boolean;
|
|
60
|
+
autoUpdate: boolean;
|
|
61
|
+
updateInterval: number;
|
|
62
|
+
minErrorCount: number;
|
|
63
|
+
skillGeneration: boolean;
|
|
64
|
+
logPath?: string;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=adaptive-documentation-types.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Types for Adaptive Documentation Bot
|
|
4
|
+
*
|
|
5
|
+
* Monitors MCP logs and automatically improves tool descriptions and skills
|
|
6
|
+
* based on actual LLM usage errors.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
//# sourceMappingURL=adaptive-documentation-types.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Activity Bot
|
|
3
|
+
*
|
|
4
|
+
* Monitors agent activity and posts summaries to discussions.
|
|
5
|
+
* Can respond to queries about agent performance and tool usage.
|
|
6
|
+
*/
|
|
7
|
+
import { AgentTracker } from './agent-tracker';
|
|
8
|
+
export interface AgentActivityBotConfig {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
postSummaryAfterConversation: boolean;
|
|
11
|
+
minDurationThreshold?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class AgentActivityBot {
|
|
14
|
+
private agentTracker;
|
|
15
|
+
private config;
|
|
16
|
+
private lastPostedConversation;
|
|
17
|
+
constructor(agentTracker: AgentTracker, config: AgentActivityBotConfig);
|
|
18
|
+
/**
|
|
19
|
+
* Generate a summary message for the last conversation in a discussion
|
|
20
|
+
*/
|
|
21
|
+
generateSummary(requestId: string, discussionId: string, duration: number, toolsCalled: string[]): string;
|
|
22
|
+
/**
|
|
23
|
+
* Format a concise summary message
|
|
24
|
+
*/
|
|
25
|
+
private formatSummaryMessage;
|
|
26
|
+
/**
|
|
27
|
+
* Generate detailed agent activity report
|
|
28
|
+
*/
|
|
29
|
+
generateDetailedReport(discussionId?: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Check if message is asking for agent activity details
|
|
32
|
+
*/
|
|
33
|
+
isActivityQuery(messageContent: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Should post summary after this conversation?
|
|
36
|
+
*/
|
|
37
|
+
shouldPostSummary(discussionId: string, duration: number): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Mark that we posted a summary for this discussion
|
|
40
|
+
*/
|
|
41
|
+
markPosted(discussionId: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get agent tracker instance
|
|
44
|
+
*/
|
|
45
|
+
getAgentTracker(): AgentTracker;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Factory function to create AgentActivityBot
|
|
49
|
+
*/
|
|
50
|
+
export declare function createAgentActivityBot(agentTracker: AgentTracker, config: AgentActivityBotConfig): AgentActivityBot;
|
|
51
|
+
//# sourceMappingURL=agent-activity-bot.d.ts.map
|