@hailer/mcp 0.1.6 → 0.1.9
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/agents/agent-dmitri-activity-crud.md +3 -1
- package/.claude/agents/agent-giuseppe-app-builder.md +11 -12
- package/.claude/agents/agent-kenji-data-reader.md +5 -3
- package/.claude/hooks/sync-marketplace-agents.cjs +117 -56
- package/.claude/skills/hailer-app-builder/SKILL.md +506 -0
- package/.claude/skills/publish-hailer-app/SKILL.md +169 -0
- package/.claude/skills/tool-parameter-usage/SKILL.md +112 -0
- package/CHANGELOG.md +20 -0
- package/CLAUDE.md +37 -16
- package/REFACTOR_STATUS.md +127 -0
- package/dist/cli.js +0 -0
- package/dist/client/agents/base.d.ts +202 -0
- package/dist/client/agents/base.js +737 -0
- package/dist/client/agents/definitions.d.ts +53 -0
- package/dist/client/agents/definitions.js +178 -0
- package/dist/client/agents/orchestrator.d.ts +119 -0
- package/dist/client/agents/orchestrator.js +760 -0
- package/dist/client/agents/specialist.d.ts +86 -0
- package/dist/client/agents/specialist.js +340 -0
- package/dist/client/bot-manager.d.ts +44 -0
- package/dist/client/bot-manager.js +173 -0
- package/dist/client/chat-agent-daemon.d.ts +464 -0
- package/dist/client/chat-agent-daemon.js +1774 -0
- package/dist/client/daemon-factory.d.ts +106 -0
- package/dist/client/daemon-factory.js +301 -0
- package/dist/client/factory.d.ts +107 -0
- package/dist/client/factory.js +304 -0
- package/dist/client/index.d.ts +17 -0
- package/dist/client/index.js +38 -0
- package/dist/client/multi-bot-manager.d.ts +18 -0
- package/dist/client/multi-bot-manager.js +88 -1
- package/dist/client/orchestrator-daemon.d.ts +87 -0
- package/dist/client/orchestrator-daemon.js +444 -0
- package/dist/client/services/agent-registry.d.ts +108 -0
- package/dist/client/services/agent-registry.js +630 -0
- package/dist/client/services/conversation-manager.d.ts +50 -0
- package/dist/client/services/conversation-manager.js +136 -0
- package/dist/client/services/mcp-client.d.ts +48 -0
- package/dist/client/services/mcp-client.js +105 -0
- package/dist/client/services/message-classifier.d.ts +37 -0
- package/dist/client/services/message-classifier.js +187 -0
- package/dist/client/services/message-formatter.d.ts +84 -0
- package/dist/client/services/message-formatter.js +353 -0
- package/dist/client/services/session-logger.d.ts +106 -0
- package/dist/client/services/session-logger.js +446 -0
- package/dist/client/services/tool-executor.d.ts +41 -0
- package/dist/client/services/tool-executor.js +169 -0
- package/dist/client/services/workspace-schema-cache.d.ts +149 -0
- package/dist/client/services/workspace-schema-cache.js +732 -0
- package/dist/client/specialist-daemon.d.ts +77 -0
- package/dist/client/specialist-daemon.js +197 -0
- package/dist/client/specialists.d.ts +53 -0
- package/dist/client/specialists.js +178 -0
- package/dist/client/tool-schema-loader.d.ts +4 -3
- package/dist/client/tool-schema-loader.js +54 -8
- package/dist/client/types.d.ts +283 -55
- package/dist/client/types.js +113 -2
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/core.d.ts +10 -2
- package/dist/core.js +43 -27
- package/dist/lib/logger.js +15 -3
- package/dist/mcp/UserContextCache.js +2 -2
- package/dist/mcp/hailer-clients.js +5 -5
- package/dist/mcp/signal-handler.js +27 -5
- package/dist/mcp/tools/activity.js +137 -65
- package/dist/mcp/tools/app-core.js +4 -140
- package/dist/mcp/tools/app-marketplace.js +15 -260
- package/dist/mcp/tools/app-member.js +2 -73
- package/dist/mcp/tools/app-scaffold.js +146 -87
- package/dist/mcp/tools/discussion.js +348 -73
- package/dist/mcp/tools/insight.js +74 -190
- package/dist/mcp/tools/workflow.js +20 -94
- package/dist/mcp/utils/hailer-api-client.d.ts +4 -2
- package/dist/mcp/utils/hailer-api-client.js +24 -10
- package/dist/mcp-server.d.ts +4 -0
- package/dist/mcp-server.js +24 -4
- package/dist/routes/agents.d.ts +44 -0
- package/dist/routes/agents.js +311 -0
- package/dist/services/agent-credential-store.d.ts +73 -0
- package/dist/services/agent-credential-store.js +212 -0
- package/lineup-manager/dist/assets/index-8ce6041d.css +1 -0
- package/lineup-manager/dist/assets/index-e168f265.js +600 -0
- package/lineup-manager/dist/index.html +15 -0
- package/lineup-manager/dist/manifest.json +17 -0
- package/lineup-manager/dist/vite.svg +1 -0
- package/package.json +1 -1
- package/dist/client/adaptive-documentation-bot.d.ts +0 -106
- package/dist/client/adaptive-documentation-bot.js +0 -464
- package/dist/client/adaptive-documentation-types.d.ts +0 -66
- package/dist/client/adaptive-documentation-types.js +0 -9
- package/dist/client/agent-activity-bot.d.ts +0 -51
- package/dist/client/agent-activity-bot.js +0 -166
- package/dist/client/agent-tracker.d.ts +0 -499
- package/dist/client/agent-tracker.js +0 -659
- package/dist/client/description-updater.d.ts +0 -56
- package/dist/client/description-updater.js +0 -259
- package/dist/client/log-parser.d.ts +0 -72
- package/dist/client/log-parser.js +0 -387
- package/dist/client/mcp-assistant.d.ts +0 -21
- package/dist/client/mcp-assistant.js +0 -58
- package/dist/client/mcp-client.d.ts +0 -50
- package/dist/client/mcp-client.js +0 -538
- package/dist/client/message-processor.d.ts +0 -35
- package/dist/client/message-processor.js +0 -357
- package/dist/client/providers/anthropic-provider.d.ts +0 -19
- package/dist/client/providers/anthropic-provider.js +0 -645
- package/dist/client/providers/assistant-provider.d.ts +0 -17
- package/dist/client/providers/assistant-provider.js +0 -51
- package/dist/client/providers/llm-provider.d.ts +0 -47
- package/dist/client/providers/llm-provider.js +0 -367
- package/dist/client/providers/openai-provider.d.ts +0 -23
- package/dist/client/providers/openai-provider.js +0 -630
- package/dist/client/simple-llm-caller.d.ts +0 -19
- package/dist/client/simple-llm-caller.js +0 -100
- package/dist/client/skill-generator.d.ts +0 -81
- package/dist/client/skill-generator.js +0 -386
- package/dist/client/test-adaptive-bot.d.ts +0 -9
- package/dist/client/test-adaptive-bot.js +0 -82
- package/dist/client/token-pricing.d.ts +0 -38
- package/dist/client/token-pricing.js +0 -127
- package/dist/client/token-tracker.d.ts +0 -232
- package/dist/client/token-tracker.js +0 -457
- package/dist/client/token-usage-bot.d.ts +0 -53
- package/dist/client/token-usage-bot.js +0 -153
- package/dist/client/tool-executor.d.ts +0 -69
- package/dist/client/tool-executor.js +0 -159
- package/dist/lib/materialize.d.ts +0 -3
- package/dist/lib/materialize.js +0 -101
- package/dist/lib/normalizedName.d.ts +0 -7
- package/dist/lib/normalizedName.js +0 -48
- package/dist/lib/terminal-prompt.d.ts +0 -9
- package/dist/lib/terminal-prompt.js +0 -108
- package/dist/mcp/tools/skill.d.ts +0 -10
- package/dist/mcp/tools/skill.js +0 -279
- package/dist/mcp/tools/workflow-template.d.ts +0 -19
- package/dist/mcp/tools/workflow-template.js +0 -822
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Vite + React + TS</title>
|
|
8
|
+
<script type="module" crossorigin src="./assets/index-e168f265.js"></script>
|
|
9
|
+
<link rel="stylesheet" href="./assets/index-8ce6041d.css">
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Magic Apps Ltd.",
|
|
3
|
+
"contributors": [
|
|
4
|
+
"John Hailero <john@magic.apps>"
|
|
5
|
+
],
|
|
6
|
+
"appId": "695816e2ba1d8bef3af7e018",
|
|
7
|
+
"config": {
|
|
8
|
+
"fields": {
|
|
9
|
+
"workflowId": {
|
|
10
|
+
"type": "string"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"version": "1.0.0",
|
|
15
|
+
"versionDescription": "Initial release",
|
|
16
|
+
"targetId": "695817ba3d3e3377c187c57a"
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/package.json
CHANGED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adaptive Documentation Bot
|
|
3
|
-
*
|
|
4
|
-
* Monitors MCP logs for tool call errors and automatically improves
|
|
5
|
-
* tool descriptions and skills based on actual LLM usage patterns.
|
|
6
|
-
*
|
|
7
|
-
* Key Features:
|
|
8
|
-
* - Detects when LLMs make mistakes calling tools
|
|
9
|
-
* - Uses LLM to analyze what went wrong
|
|
10
|
-
* - Automatically updates tool descriptions
|
|
11
|
-
* - Creates/updates skill documents with common mistakes
|
|
12
|
-
* - Learns and improves over time
|
|
13
|
-
*/
|
|
14
|
-
import { ToolCallError, ErrorPattern, AdaptiveBotConfig } from './adaptive-documentation-types';
|
|
15
|
-
export declare class AdaptiveDocumentationBot {
|
|
16
|
-
private logParser;
|
|
17
|
-
private descriptionUpdater;
|
|
18
|
-
private llmCaller;
|
|
19
|
-
private config;
|
|
20
|
-
private errorPatterns;
|
|
21
|
-
private monitoringInterval?;
|
|
22
|
-
private isMonitoring;
|
|
23
|
-
constructor(apiKey: string, provider?: 'anthropic' | 'openai', config?: Partial<AdaptiveBotConfig>);
|
|
24
|
-
/**
|
|
25
|
-
* Start monitoring logs for errors
|
|
26
|
-
*/
|
|
27
|
-
startMonitoring(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Analyze logs immediately after a conversation ends
|
|
30
|
-
* Called by MCP Client after each bot conversation
|
|
31
|
-
*/
|
|
32
|
-
analyzeAfterConversation(): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Report error directly (not from logs)
|
|
35
|
-
* Use this to capture errors from active conversations
|
|
36
|
-
*/
|
|
37
|
-
reportError(error: ToolCallError): void;
|
|
38
|
-
/**
|
|
39
|
-
* Stop monitoring logs
|
|
40
|
-
*/
|
|
41
|
-
stopMonitoring(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Main monitoring loop: parse errors and apply improvements
|
|
44
|
-
*/
|
|
45
|
-
private monitorAndImprove;
|
|
46
|
-
/**
|
|
47
|
-
* Update error patterns with new errors
|
|
48
|
-
*/
|
|
49
|
-
private updateErrorPatterns;
|
|
50
|
-
/**
|
|
51
|
-
* Analyze error pattern and apply improvements
|
|
52
|
-
*/
|
|
53
|
-
private analyzeAndImprove;
|
|
54
|
-
/**
|
|
55
|
-
* Analyze error pattern using LLM
|
|
56
|
-
*/
|
|
57
|
-
private analyzeWithLLM;
|
|
58
|
-
/**
|
|
59
|
-
* Apply improvements based on analysis
|
|
60
|
-
*/
|
|
61
|
-
private applyImprovements;
|
|
62
|
-
/**
|
|
63
|
-
* Generate improved description using LLM
|
|
64
|
-
*/
|
|
65
|
-
private generateImprovedDescription;
|
|
66
|
-
/**
|
|
67
|
-
* Generate improved parameter description using LLM
|
|
68
|
-
*/
|
|
69
|
-
private generateImprovedParameterDescription;
|
|
70
|
-
/**
|
|
71
|
-
* Generate pattern key for grouping similar errors
|
|
72
|
-
*/
|
|
73
|
-
private getPatternKey;
|
|
74
|
-
/**
|
|
75
|
-
* Generate human-readable description for error pattern
|
|
76
|
-
*/
|
|
77
|
-
private generatePatternDescription;
|
|
78
|
-
/**
|
|
79
|
-
* Get statistics about adaptive bot performance
|
|
80
|
-
*/
|
|
81
|
-
getStats(): {
|
|
82
|
-
monitoring: boolean;
|
|
83
|
-
errorPatterns: number;
|
|
84
|
-
improvements: any;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Get error patterns for a specific tool
|
|
88
|
-
*/
|
|
89
|
-
getToolErrorPatterns(toolName: string): ErrorPattern[];
|
|
90
|
-
/**
|
|
91
|
-
* Test mode - parse errors and show what would be improved (without applying changes)
|
|
92
|
-
*/
|
|
93
|
-
testRun(): Promise<{
|
|
94
|
-
errors: ToolCallError[];
|
|
95
|
-
patterns: ErrorPattern[];
|
|
96
|
-
suggestions: Array<{
|
|
97
|
-
toolName: string;
|
|
98
|
-
errorCount: number;
|
|
99
|
-
errorMessage: string;
|
|
100
|
-
existingSkill?: string;
|
|
101
|
-
wouldCreateSkill: boolean;
|
|
102
|
-
wouldUpdateSkill: boolean;
|
|
103
|
-
}>;
|
|
104
|
-
}>;
|
|
105
|
-
}
|
|
106
|
-
//# sourceMappingURL=adaptive-documentation-bot.d.ts.map
|
|
@@ -1,464 +0,0 @@
|
|
|
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 simple_llm_caller_1 = require("./simple-llm-caller");
|
|
21
|
-
const logger = (0, logger_1.createLogger)({ component: 'AdaptiveDocumentationBot' });
|
|
22
|
-
class AdaptiveDocumentationBot {
|
|
23
|
-
logParser;
|
|
24
|
-
descriptionUpdater;
|
|
25
|
-
llmCaller;
|
|
26
|
-
config;
|
|
27
|
-
errorPatterns = new Map();
|
|
28
|
-
monitoringInterval;
|
|
29
|
-
isMonitoring = false;
|
|
30
|
-
constructor(apiKey, provider = 'anthropic', config = {}) {
|
|
31
|
-
this.llmCaller = new simple_llm_caller_1.SimpleLLMCaller(provider, apiKey);
|
|
32
|
-
this.config = {
|
|
33
|
-
enabled: config.enabled ?? true,
|
|
34
|
-
autoUpdate: config.autoUpdate ?? true,
|
|
35
|
-
updateInterval: config.updateInterval ?? 60000, // 1 minute
|
|
36
|
-
minErrorCount: config.minErrorCount ?? 3,
|
|
37
|
-
skillGeneration: config.skillGeneration ?? true,
|
|
38
|
-
logPath: config.logPath
|
|
39
|
-
};
|
|
40
|
-
this.logParser = new log_parser_1.LogParser(this.config.logPath);
|
|
41
|
-
this.descriptionUpdater = new description_updater_1.DescriptionUpdater();
|
|
42
|
-
logger.info('Adaptive Documentation Bot initialized', {
|
|
43
|
-
autoUpdate: this.config.autoUpdate,
|
|
44
|
-
updateInterval: this.config.updateInterval,
|
|
45
|
-
minErrorCount: this.config.minErrorCount
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Start monitoring logs for errors
|
|
50
|
-
*/
|
|
51
|
-
startMonitoring() {
|
|
52
|
-
if (this.isMonitoring) {
|
|
53
|
-
logger.warn('Already monitoring logs');
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
this.isMonitoring = true;
|
|
57
|
-
logger.info('🔍 Started monitoring MCP logs for tool call errors');
|
|
58
|
-
// Run immediately
|
|
59
|
-
this.monitorAndImprove().catch(error => {
|
|
60
|
-
logger.error('Error in monitoring loop', error);
|
|
61
|
-
});
|
|
62
|
-
// Then run on interval (as backup)
|
|
63
|
-
this.monitoringInterval = setInterval(() => {
|
|
64
|
-
this.monitorAndImprove().catch(error => {
|
|
65
|
-
logger.error('Error in monitoring loop', error);
|
|
66
|
-
});
|
|
67
|
-
}, this.config.updateInterval);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Analyze logs immediately after a conversation ends
|
|
71
|
-
* Called by MCP Client after each bot conversation
|
|
72
|
-
*/
|
|
73
|
-
async analyzeAfterConversation() {
|
|
74
|
-
if (!this.isMonitoring) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
logger.debug('🔍 Analyzing logs after conversation completion');
|
|
78
|
-
// Wait 500ms for logger to finish writing
|
|
79
|
-
// This prevents race condition where we try to read while logger is mid-write
|
|
80
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
81
|
-
try {
|
|
82
|
-
await this.monitorAndImprove();
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
logger.error('Failed to analyze after conversation', error);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Report error directly (not from logs)
|
|
90
|
-
* Use this to capture errors from active conversations
|
|
91
|
-
*/
|
|
92
|
-
reportError(error) {
|
|
93
|
-
if (!this.isMonitoring) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const key = this.getPatternKey(error);
|
|
97
|
-
const existing = this.errorPatterns.get(key);
|
|
98
|
-
if (existing) {
|
|
99
|
-
existing.count++;
|
|
100
|
-
existing.lastSeen = error.timestamp;
|
|
101
|
-
existing.examples.push(error);
|
|
102
|
-
logger.debug('Updated error pattern', {
|
|
103
|
-
pattern: key,
|
|
104
|
-
count: existing.count
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
this.errorPatterns.set(key, {
|
|
109
|
-
pattern: key,
|
|
110
|
-
description: this.generatePatternDescription(error),
|
|
111
|
-
count: 1,
|
|
112
|
-
lastSeen: error.timestamp,
|
|
113
|
-
firstSeen: error.timestamp,
|
|
114
|
-
examples: [error]
|
|
115
|
-
});
|
|
116
|
-
logger.debug('New error pattern detected', {
|
|
117
|
-
pattern: key,
|
|
118
|
-
toolName: error.toolName
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
// Check if we should analyze this error immediately
|
|
122
|
-
const pattern = this.errorPatterns.get(key);
|
|
123
|
-
if (pattern && pattern.count >= this.config.minErrorCount && !pattern.suggestedFix) {
|
|
124
|
-
logger.info('Error threshold reached, analyzing immediately', {
|
|
125
|
-
toolName: error.toolName,
|
|
126
|
-
count: pattern.count
|
|
127
|
-
});
|
|
128
|
-
// Analyze asynchronously
|
|
129
|
-
this.analyzeAndImprove(pattern).catch(err => {
|
|
130
|
-
logger.error('Failed to analyze error immediately', err);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Stop monitoring logs
|
|
136
|
-
*/
|
|
137
|
-
stopMonitoring() {
|
|
138
|
-
if (this.monitoringInterval) {
|
|
139
|
-
clearInterval(this.monitoringInterval);
|
|
140
|
-
this.monitoringInterval = undefined;
|
|
141
|
-
}
|
|
142
|
-
this.isMonitoring = false;
|
|
143
|
-
logger.info('Stopped monitoring MCP logs');
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Main monitoring loop: parse errors and apply improvements
|
|
147
|
-
*/
|
|
148
|
-
async monitorAndImprove() {
|
|
149
|
-
try {
|
|
150
|
-
// 1. Parse logs for new errors
|
|
151
|
-
const errors = await this.logParser.parseToolCallErrors();
|
|
152
|
-
if (errors.length === 0) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
logger.info('📊 Detected tool call errors', {
|
|
156
|
-
count: errors.length,
|
|
157
|
-
uniqueTools: new Set(errors.map(e => e.toolName)).size
|
|
158
|
-
});
|
|
159
|
-
// 2. Group errors by tool and pattern
|
|
160
|
-
this.updateErrorPatterns(errors);
|
|
161
|
-
// 3. Analyze and improve tools that meet minimum error threshold
|
|
162
|
-
for (const pattern of this.errorPatterns.values()) {
|
|
163
|
-
if (pattern.count >= this.config.minErrorCount && !pattern.suggestedFix) {
|
|
164
|
-
await this.analyzeAndImprove(pattern);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
logger.error('Failed to monitor and improve', error);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Update error patterns with new errors
|
|
174
|
-
*/
|
|
175
|
-
updateErrorPatterns(errors) {
|
|
176
|
-
for (const error of errors) {
|
|
177
|
-
const key = this.getPatternKey(error);
|
|
178
|
-
const existing = this.errorPatterns.get(key);
|
|
179
|
-
if (existing) {
|
|
180
|
-
existing.count++;
|
|
181
|
-
existing.lastSeen = error.timestamp;
|
|
182
|
-
existing.examples.push(error);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
this.errorPatterns.set(key, {
|
|
186
|
-
pattern: key,
|
|
187
|
-
description: this.generatePatternDescription(error),
|
|
188
|
-
count: 1,
|
|
189
|
-
lastSeen: error.timestamp,
|
|
190
|
-
firstSeen: error.timestamp,
|
|
191
|
-
examples: [error]
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Analyze error pattern and apply improvements
|
|
198
|
-
*/
|
|
199
|
-
async analyzeAndImprove(pattern) {
|
|
200
|
-
try {
|
|
201
|
-
logger.info('🔍 Analyzing error pattern', {
|
|
202
|
-
pattern: pattern.pattern,
|
|
203
|
-
count: pattern.count,
|
|
204
|
-
tool: pattern.examples[0].toolName
|
|
205
|
-
});
|
|
206
|
-
// 1. Analyze with LLM
|
|
207
|
-
const analysis = await this.analyzeWithLLM(pattern);
|
|
208
|
-
if (!analysis.isDescriptionIssue && !analysis.needsSkill) {
|
|
209
|
-
logger.debug('No action needed for this error pattern', {
|
|
210
|
-
pattern: pattern.pattern
|
|
211
|
-
});
|
|
212
|
-
pattern.suggestedFix = 'no-action-needed';
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
// 2. Apply improvements based on analysis
|
|
216
|
-
if (this.config.autoUpdate) {
|
|
217
|
-
await this.applyImprovements(pattern, analysis);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
logger.info('Auto-update disabled, would improve:', {
|
|
221
|
-
tool: pattern.examples[0].toolName,
|
|
222
|
-
analysis
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
// Mark as processed
|
|
226
|
-
pattern.suggestedFix = 'applied';
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
logger.error('Failed to analyze and improve pattern', error, {
|
|
230
|
-
pattern: pattern.pattern
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Analyze error pattern using LLM
|
|
236
|
-
*/
|
|
237
|
-
async analyzeWithLLM(pattern) {
|
|
238
|
-
const example = pattern.examples[0];
|
|
239
|
-
const prompt = `You are analyzing MCP tool call errors to improve tool descriptions for an internal chat bot.
|
|
240
|
-
|
|
241
|
-
**IMPORTANT CONTEXT**: This chat bot CANNOT use skills (it only has READ + WRITE tools, no get_skill capability).
|
|
242
|
-
All improvements must be in the tool description itself, not in external skill documents.
|
|
243
|
-
|
|
244
|
-
**Tool**: ${example.toolName}
|
|
245
|
-
**Error Message**: ${example.errorMessage}
|
|
246
|
-
**Error Count**: ${pattern.count} times
|
|
247
|
-
**Example Attempted Call**:
|
|
248
|
-
\`\`\`json
|
|
249
|
-
${JSON.stringify(example.attemptedCall, null, 2)}
|
|
250
|
-
\`\`\`
|
|
251
|
-
|
|
252
|
-
Analyze this error and respond in JSON format:
|
|
253
|
-
{
|
|
254
|
-
"isDescriptionIssue": boolean (true if the tool description is unclear - ALWAYS true since bot can't use skills),
|
|
255
|
-
"needsSkill": boolean (ALWAYS false - bot cannot access skills, only external Claude Code users can),
|
|
256
|
-
"problem": "string (what was misunderstood in the current description)",
|
|
257
|
-
"suggestion": "string (how to improve the description INLINE with examples and clear requirements)",
|
|
258
|
-
"priority": "low" | "medium" | "high" | "critical",
|
|
259
|
-
"affectedParameter": "string (if specific parameter caused issue)",
|
|
260
|
-
"incorrectUsage": {...} (the wrong way LLM used it),
|
|
261
|
-
"correctUsage": {...} (the correct way to use it)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
Focus on:
|
|
265
|
-
1. What did the LLM misunderstand from the current description?
|
|
266
|
-
2. Which required parameters are not clearly marked as REQUIRED?
|
|
267
|
-
3. What format requirements are missing or unclear?
|
|
268
|
-
4. Add inline examples directly in the description (NOT in skills)
|
|
269
|
-
5. Use ⚠️ REQUIRED or ✅ EXAMPLE markers in the description
|
|
270
|
-
|
|
271
|
-
Return ONLY valid JSON, no other text.`;
|
|
272
|
-
try {
|
|
273
|
-
const response = await this.llmCaller.generate(prompt, 'You are a technical documentation expert. Analyze errors and suggest improvements.');
|
|
274
|
-
// Extract JSON from response
|
|
275
|
-
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
276
|
-
if (!jsonMatch) {
|
|
277
|
-
throw new Error('LLM response did not contain JSON');
|
|
278
|
-
}
|
|
279
|
-
const analysis = JSON.parse(jsonMatch[0]);
|
|
280
|
-
logger.debug('LLM analysis complete', { analysis });
|
|
281
|
-
return analysis;
|
|
282
|
-
}
|
|
283
|
-
catch (error) {
|
|
284
|
-
logger.error('Failed to analyze with LLM', error);
|
|
285
|
-
// Return conservative default
|
|
286
|
-
return {
|
|
287
|
-
isDescriptionIssue: true,
|
|
288
|
-
needsSkill: pattern.count >= 5,
|
|
289
|
-
problem: 'Analysis failed - assuming description issue',
|
|
290
|
-
suggestion: 'Add clearer examples and emphasize critical requirements',
|
|
291
|
-
priority: 'medium'
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Apply improvements based on analysis
|
|
297
|
-
*/
|
|
298
|
-
async applyImprovements(pattern, analysis) {
|
|
299
|
-
const toolName = pattern.examples[0].toolName;
|
|
300
|
-
// 1. Update description if needed
|
|
301
|
-
if (analysis.isDescriptionIssue) {
|
|
302
|
-
const improved = await this.generateImprovedDescription(toolName, pattern, analysis);
|
|
303
|
-
if (improved) {
|
|
304
|
-
await this.descriptionUpdater.updateToolDescription(toolName, improved, analysis.problem, pattern.examples[0]);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// 2. Update parameter description if specific parameter issue
|
|
308
|
-
if (analysis.affectedParameter) {
|
|
309
|
-
const paramImproved = await this.generateImprovedParameterDescription(toolName, analysis.affectedParameter, analysis);
|
|
310
|
-
if (paramImproved) {
|
|
311
|
-
await this.descriptionUpdater.updateParameterDescription(toolName, analysis.affectedParameter, paramImproved, analysis.problem);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
// 3. Skill generation disabled (skills moved to docs/)
|
|
315
|
-
logger.info('✅ Improvements applied', {
|
|
316
|
-
tool: toolName,
|
|
317
|
-
descriptionUpdated: analysis.isDescriptionIssue,
|
|
318
|
-
parameterUpdated: !!analysis.affectedParameter,
|
|
319
|
-
skillUpdated: analysis.needsSkill && this.config.skillGeneration
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Generate improved description using LLM
|
|
324
|
-
*/
|
|
325
|
-
async generateImprovedDescription(toolName, pattern, analysis) {
|
|
326
|
-
// Get current description (would need to read from tool files)
|
|
327
|
-
// For now, generate based on analysis
|
|
328
|
-
const prompt = `Generate an improved tool description for "${toolName}" for a chat bot that CANNOT load external skills.
|
|
329
|
-
|
|
330
|
-
**Problem**: ${analysis.problem}
|
|
331
|
-
**Suggestion**: ${analysis.suggestion}
|
|
332
|
-
**Error Count**: ${pattern.count} times
|
|
333
|
-
**Incorrect Usage (what the bot did WRONG)**: ${JSON.stringify(analysis.incorrectUsage)}
|
|
334
|
-
**Correct Usage (what it SHOULD do)**: ${JSON.stringify(analysis.correctUsage)}
|
|
335
|
-
|
|
336
|
-
CRITICAL Requirements:
|
|
337
|
-
1. Show BOTH the wrong and right way - use ✅ CORRECT: and ❌ WRONG: labels
|
|
338
|
-
2. Include the ACTUAL incorrect JSON that was attempted
|
|
339
|
-
3. Be EXTREMELY explicit about parameter types (string vs array, required vs optional)
|
|
340
|
-
4. Use ⚠️ CRITICAL: for the most important requirement
|
|
341
|
-
5. Keep description under 400 characters for readability
|
|
342
|
-
|
|
343
|
-
Example format that SHOWS the contrast:
|
|
344
|
-
"📋 [Brief description]. ⚠️ CRITICAL: workflowId must be STRING (NOT array!), phaseId is REQUIRED. ✅ CORRECT: {"workflowId": "abc123", "phaseId": "xyz"} ❌ WRONG: {"workflowId": ["abc123"]} (causes validation error)"
|
|
345
|
-
|
|
346
|
-
Return ONLY the improved description text, no JSON or extra formatting.`;
|
|
347
|
-
try {
|
|
348
|
-
const improved = await this.llmCaller.generate(prompt, 'You are a technical writer. Write clear, concise tool descriptions.');
|
|
349
|
-
return improved.trim();
|
|
350
|
-
}
|
|
351
|
-
catch (error) {
|
|
352
|
-
logger.error('Failed to generate improved description', error);
|
|
353
|
-
return null;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Generate improved parameter description using LLM
|
|
358
|
-
*/
|
|
359
|
-
async generateImprovedParameterDescription(toolName, parameterName, analysis) {
|
|
360
|
-
const prompt = `Generate an improved parameter description for "${parameterName}" in tool "${toolName}".
|
|
361
|
-
|
|
362
|
-
**Problem**: ${analysis.problem}
|
|
363
|
-
**Incorrect Usage**:
|
|
364
|
-
\`\`\`json
|
|
365
|
-
${JSON.stringify(analysis.incorrectUsage, null, 2)}
|
|
366
|
-
\`\`\`
|
|
367
|
-
|
|
368
|
-
**Correct Usage**:
|
|
369
|
-
\`\`\`json
|
|
370
|
-
${JSON.stringify(analysis.correctUsage, null, 2)}
|
|
371
|
-
\`\`\`
|
|
372
|
-
|
|
373
|
-
Requirements:
|
|
374
|
-
- Be specific about format/type requirements
|
|
375
|
-
- Use ⚠️ CRITICAL or ✅ CORRECT for emphasis
|
|
376
|
-
- Include example format if helpful
|
|
377
|
-
- Keep it under 100 words
|
|
378
|
-
|
|
379
|
-
Return ONLY the improved description text.`;
|
|
380
|
-
try {
|
|
381
|
-
const improved = await this.llmCaller.generate(prompt, 'You are a technical writer. Write clear parameter descriptions.');
|
|
382
|
-
return improved.trim();
|
|
383
|
-
}
|
|
384
|
-
catch (error) {
|
|
385
|
-
logger.error('Failed to generate improved parameter description', error);
|
|
386
|
-
return null;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Generate pattern key for grouping similar errors
|
|
391
|
-
*/
|
|
392
|
-
getPatternKey(error) {
|
|
393
|
-
// Group by tool name and error message pattern
|
|
394
|
-
return `${error.toolName}:${error.errorMessage}`;
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Generate human-readable description for error pattern
|
|
398
|
-
*/
|
|
399
|
-
generatePatternDescription(error) {
|
|
400
|
-
const message = error.errorMessage.toLowerCase();
|
|
401
|
-
if (message.includes('required') || message.includes('missing')) {
|
|
402
|
-
return 'Missing required parameter';
|
|
403
|
-
}
|
|
404
|
-
else if (message.includes('validation') || message.includes('invalid')) {
|
|
405
|
-
return 'Parameter validation failed';
|
|
406
|
-
}
|
|
407
|
-
else if (message.includes('format') || message.includes('type')) {
|
|
408
|
-
return 'Incorrect parameter format';
|
|
409
|
-
}
|
|
410
|
-
else {
|
|
411
|
-
return 'Tool call error';
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Get statistics about adaptive bot performance
|
|
416
|
-
*/
|
|
417
|
-
getStats() {
|
|
418
|
-
return {
|
|
419
|
-
monitoring: this.isMonitoring,
|
|
420
|
-
errorPatterns: this.errorPatterns.size,
|
|
421
|
-
improvements: this.descriptionUpdater.getStats()
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Get error patterns for a specific tool
|
|
426
|
-
*/
|
|
427
|
-
getToolErrorPatterns(toolName) {
|
|
428
|
-
const patterns = [];
|
|
429
|
-
for (const pattern of this.errorPatterns.values()) {
|
|
430
|
-
if (pattern.examples[0].toolName === toolName) {
|
|
431
|
-
patterns.push(pattern);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
return patterns;
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Test mode - parse errors and show what would be improved (without applying changes)
|
|
438
|
-
*/
|
|
439
|
-
async testRun() {
|
|
440
|
-
const errors = await this.logParser.parseToolCallErrors();
|
|
441
|
-
this.updateErrorPatterns(errors);
|
|
442
|
-
const suggestions = [];
|
|
443
|
-
for (const pattern of this.errorPatterns.values()) {
|
|
444
|
-
if (pattern.count >= this.config.minErrorCount && !pattern.suggestedFix) {
|
|
445
|
-
const toolName = pattern.examples[0].toolName;
|
|
446
|
-
suggestions.push({
|
|
447
|
-
toolName,
|
|
448
|
-
errorCount: pattern.count,
|
|
449
|
-
errorMessage: pattern.examples[0].errorMessage,
|
|
450
|
-
existingSkill: undefined,
|
|
451
|
-
wouldCreateSkill: false,
|
|
452
|
-
wouldUpdateSkill: false
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
return {
|
|
457
|
-
errors,
|
|
458
|
-
patterns: Array.from(this.errorPatterns.values()),
|
|
459
|
-
suggestions
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
exports.AdaptiveDocumentationBot = AdaptiveDocumentationBot;
|
|
464
|
-
//# sourceMappingURL=adaptive-documentation-bot.js.map
|
|
@@ -1,66 +0,0 @@
|
|
|
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
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|