@defai.digital/ax-cli 3.7.2 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -53
- package/dist/agent/context-manager.d.ts +15 -1
- package/dist/agent/context-manager.js +50 -19
- package/dist/agent/context-manager.js.map +1 -1
- package/dist/agent/dependency-resolver.js +13 -7
- package/dist/agent/dependency-resolver.js.map +1 -1
- package/dist/agent/llm-agent.d.ts +37 -0
- package/dist/agent/llm-agent.js +318 -98
- package/dist/agent/llm-agent.js.map +1 -1
- package/dist/agent/status-reporter.d.ts +114 -0
- package/dist/agent/status-reporter.js +335 -0
- package/dist/agent/status-reporter.js.map +1 -0
- package/dist/analyzers/best-practices/rules/typescript/no-magic-numbers.js +8 -2
- package/dist/analyzers/best-practices/rules/typescript/no-magic-numbers.js.map +1 -1
- package/dist/analyzers/best-practices/rules/typescript/no-unused-vars.js +3 -1
- package/dist/analyzers/best-practices/rules/typescript/no-unused-vars.js.map +1 -1
- package/dist/analyzers/best-practices/rules/typescript/prefer-const.js +3 -1
- package/dist/analyzers/best-practices/rules/typescript/prefer-const.js.map +1 -1
- package/dist/analyzers/best-practices/rules/typescript/prefer-readonly.js +3 -1
- package/dist/analyzers/best-practices/rules/typescript/prefer-readonly.js.map +1 -1
- package/dist/analyzers/code-smells/detectors/duplicate-code-detector.js +9 -3
- package/dist/analyzers/code-smells/detectors/duplicate-code-detector.js.map +1 -1
- package/dist/analyzers/git/churn-calculator.d.ts +2 -0
- package/dist/analyzers/git/churn-calculator.js +42 -8
- package/dist/analyzers/git/churn-calculator.js.map +1 -1
- package/dist/analyzers/git/hotspot-detector.js +2 -2
- package/dist/analyzers/git/hotspot-detector.js.map +1 -1
- package/dist/analyzers/metrics/metrics-analyzer.js +1 -1
- package/dist/analyzers/metrics/metrics-analyzer.js.map +1 -1
- package/dist/analyzers/security/security-analyzer.js +1 -1
- package/dist/analyzers/security/security-analyzer.js.map +1 -1
- package/dist/checkpoint/manager.d.ts +1 -0
- package/dist/checkpoint/manager.js +49 -9
- package/dist/checkpoint/manager.js.map +1 -1
- package/dist/checkpoint/storage.js +2 -2
- package/dist/checkpoint/storage.js.map +1 -1
- package/dist/commands/mcp-migrate.d.ts +9 -0
- package/dist/commands/mcp-migrate.js +172 -0
- package/dist/commands/mcp-migrate.js.map +1 -0
- package/dist/commands/status.d.ts +7 -0
- package/dist/commands/status.js +211 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/vscode.d.ts +7 -0
- package/dist/commands/vscode.js +363 -0
- package/dist/commands/vscode.js.map +1 -0
- package/dist/index.js +79 -30
- package/dist/index.js.map +1 -1
- package/dist/llm/client.js +33 -4
- package/dist/llm/client.js.map +1 -1
- package/dist/mcp/automatosx-loader.d.ts +84 -0
- package/dist/mcp/automatosx-loader.js +238 -0
- package/dist/mcp/automatosx-loader.js.map +1 -0
- package/dist/mcp/client-mutex-patch.d.ts +36 -0
- package/dist/mcp/client-mutex-patch.js +75 -0
- package/dist/mcp/client-mutex-patch.js.map +1 -0
- package/dist/mcp/client-v2.d.ts +229 -0
- package/dist/mcp/client-v2.js +740 -0
- package/dist/mcp/client-v2.js.map +1 -0
- package/dist/mcp/client.d.ts +111 -13
- package/dist/mcp/client.js +168 -253
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/config-detector-v2.d.ts +83 -0
- package/dist/mcp/config-detector-v2.js +328 -0
- package/dist/mcp/config-detector-v2.js.map +1 -0
- package/dist/mcp/config-detector.d.ts +90 -0
- package/dist/mcp/config-detector.js +242 -0
- package/dist/mcp/config-detector.js.map +1 -0
- package/dist/mcp/config-migrator-v2.d.ts +89 -0
- package/dist/mcp/config-migrator-v2.js +288 -0
- package/dist/mcp/config-migrator-v2.js.map +1 -0
- package/dist/mcp/config-migrator.d.ts +63 -0
- package/dist/mcp/config-migrator.js +269 -0
- package/dist/mcp/config-migrator.js.map +1 -0
- package/dist/mcp/config-v2.d.ts +106 -0
- package/dist/mcp/config-v2.js +417 -0
- package/dist/mcp/config-v2.js.map +1 -0
- package/dist/mcp/config.d.ts +12 -1
- package/dist/mcp/config.js +95 -10
- package/dist/mcp/config.js.map +1 -1
- package/dist/mcp/error-formatter.d.ts +46 -0
- package/dist/mcp/error-formatter.js +244 -0
- package/dist/mcp/error-formatter.js.map +1 -0
- package/dist/mcp/health.d.ts +5 -0
- package/dist/mcp/health.js +22 -2
- package/dist/mcp/health.js.map +1 -1
- package/dist/mcp/invariants.d.ts +141 -0
- package/dist/mcp/invariants.js +243 -0
- package/dist/mcp/invariants.js.map +1 -0
- package/dist/mcp/mutex-safe.d.ts +153 -0
- package/dist/mcp/mutex-safe.js +260 -0
- package/dist/mcp/mutex-safe.js.map +1 -0
- package/dist/mcp/mutex.d.ts +73 -0
- package/dist/mcp/mutex.js +137 -0
- package/dist/mcp/mutex.js.map +1 -0
- package/dist/mcp/reconnection.d.ts +4 -0
- package/dist/mcp/reconnection.js +25 -1
- package/dist/mcp/reconnection.js.map +1 -1
- package/dist/mcp/transports-v2.d.ts +152 -0
- package/dist/mcp/transports-v2.js +481 -0
- package/dist/mcp/transports-v2.js.map +1 -0
- package/dist/mcp/type-safety.d.ts +231 -0
- package/dist/mcp/type-safety.js +273 -0
- package/dist/mcp/type-safety.js.map +1 -0
- package/dist/planner/task-planner.js +13 -0
- package/dist/planner/task-planner.js.map +1 -1
- package/dist/planner/types.d.ts +6 -6
- package/dist/schemas/confirmation-schemas.d.ts +2 -2
- package/dist/schemas/settings-schemas.d.ts +196 -0
- package/dist/schemas/settings-schemas.js +146 -5
- package/dist/schemas/settings-schemas.js.map +1 -1
- package/dist/sdk/index.d.ts +118 -2
- package/dist/sdk/index.js +146 -4
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/testing.d.ts +182 -0
- package/dist/sdk/testing.js +231 -0
- package/dist/sdk/testing.js.map +1 -1
- package/dist/sdk/version.d.ts +114 -15
- package/dist/sdk/version.js +137 -15
- package/dist/sdk/version.js.map +1 -1
- package/dist/tools/bash.js +54 -9
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/registry.d.ts +146 -0
- package/dist/tools/registry.js +170 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/search.js +12 -2
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/text-editor.js +84 -26
- package/dist/tools/text-editor.js.map +1 -1
- package/dist/ui/components/chat-history.js +6 -1
- package/dist/ui/components/chat-history.js.map +1 -1
- package/dist/ui/components/chat-input.d.ts +2 -1
- package/dist/ui/components/chat-input.js +5 -2
- package/dist/ui/components/chat-input.js.map +1 -1
- package/dist/ui/components/chat-interface.js +187 -5
- package/dist/ui/components/chat-interface.js.map +1 -1
- package/dist/ui/components/context-breakdown.d.ts +23 -0
- package/dist/ui/components/context-breakdown.js +124 -0
- package/dist/ui/components/context-breakdown.js.map +1 -0
- package/dist/ui/components/keyboard-help.d.ts +17 -0
- package/dist/ui/components/keyboard-help.js +116 -0
- package/dist/ui/components/keyboard-help.js.map +1 -0
- package/dist/ui/components/keyboard-hints.js +2 -2
- package/dist/ui/components/keyboard-hints.js.map +1 -1
- package/dist/ui/components/quick-actions.js +43 -7
- package/dist/ui/components/quick-actions.js.map +1 -1
- package/dist/ui/components/status-bar.d.ts +3 -0
- package/dist/ui/components/status-bar.js +25 -16
- package/dist/ui/components/status-bar.js.map +1 -1
- package/dist/ui/components/toast-notification.d.ts +42 -0
- package/dist/ui/components/toast-notification.js +30 -2
- package/dist/ui/components/toast-notification.js.map +1 -1
- package/dist/ui/components/tool-group-display.js +34 -4
- package/dist/ui/components/tool-group-display.js.map +1 -1
- package/dist/ui/components/welcome-panel.js +2 -2
- package/dist/ui/components/welcome-panel.js.map +1 -1
- package/dist/ui/hooks/use-enhanced-input.d.ts +9 -1
- package/dist/ui/hooks/use-enhanced-input.js +901 -90
- package/dist/ui/hooks/use-enhanced-input.js.map +1 -1
- package/dist/ui/hooks/use-input-handler.d.ts +11 -1
- package/dist/ui/hooks/use-input-handler.js +67 -3
- package/dist/ui/hooks/use-input-handler.js.map +1 -1
- package/dist/ui/hooks/use-input-history.d.ts +1 -1
- package/dist/ui/hooks/use-input-history.js +50 -14
- package/dist/ui/hooks/use-input-history.js.map +1 -1
- package/dist/ui/utils/bracketed-paste-handler.d.ts +97 -0
- package/dist/ui/utils/bracketed-paste-handler.js +322 -0
- package/dist/ui/utils/bracketed-paste-handler.js.map +1 -0
- package/dist/ui/utils/change-summarizer.js +16 -6
- package/dist/ui/utils/change-summarizer.js.map +1 -1
- package/dist/ui/utils/tool-grouper.d.ts +10 -1
- package/dist/ui/utils/tool-grouper.js +143 -30
- package/dist/ui/utils/tool-grouper.js.map +1 -1
- package/dist/utils/auto-accept-logger.d.ts +173 -0
- package/dist/utils/auto-accept-logger.js +420 -0
- package/dist/utils/auto-accept-logger.js.map +1 -0
- package/dist/utils/background-task-manager.d.ts +11 -0
- package/dist/utils/background-task-manager.js +124 -38
- package/dist/utils/background-task-manager.js.map +1 -1
- package/dist/utils/confirmation-service.d.ts +1 -0
- package/dist/utils/confirmation-service.js +6 -1
- package/dist/utils/confirmation-service.js.map +1 -1
- package/dist/utils/encryption.d.ts +8 -0
- package/dist/utils/encryption.js +44 -27
- package/dist/utils/encryption.js.map +1 -1
- package/dist/utils/enhanced-error-messages.d.ts +33 -0
- package/dist/utils/enhanced-error-messages.js +420 -0
- package/dist/utils/enhanced-error-messages.js.map +1 -0
- package/dist/utils/error-handler.d.ts +13 -3
- package/dist/utils/error-handler.js +16 -4
- package/dist/utils/error-handler.js.map +1 -1
- package/dist/utils/external-editor.d.ts +47 -0
- package/dist/utils/external-editor.js +179 -0
- package/dist/utils/external-editor.js.map +1 -0
- package/dist/utils/history-migration.d.ts +9 -0
- package/dist/utils/history-migration.js +36 -0
- package/dist/utils/history-migration.js.map +1 -0
- package/dist/utils/paste-utils.js +12 -11
- package/dist/utils/paste-utils.js.map +1 -1
- package/dist/utils/rate-limiter.js +20 -1
- package/dist/utils/rate-limiter.js.map +1 -1
- package/dist/utils/safety-rules.d.ts +64 -0
- package/dist/utils/safety-rules.js +225 -0
- package/dist/utils/safety-rules.js.map +1 -0
- package/dist/utils/settings-manager.d.ts +89 -1
- package/dist/utils/settings-manager.js +359 -3
- package/dist/utils/settings-manager.js.map +1 -1
- package/dist/utils/token-counter.d.ts +2 -0
- package/dist/utils/token-counter.js +32 -9
- package/dist/utils/token-counter.js.map +1 -1
- package/dist/utils/version.d.ts +11 -2
- package/dist/utils/version.js +54 -21
- package/dist/utils/version.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AutomatosX Configuration Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads MCP server configurations from AutomatosX config files and merges
|
|
5
|
+
* them with ax-cli configurations. Provides backward compatibility for
|
|
6
|
+
* AutomatosX users migrating to ax-cli.
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { migrateConfig } from './config-migrator.js';
|
|
11
|
+
import { detectConfigFormat } from './config-detector.js';
|
|
12
|
+
/**
|
|
13
|
+
* Get AutomatosX config directory path
|
|
14
|
+
*/
|
|
15
|
+
export function getAutomatosXConfigDir(projectRoot) {
|
|
16
|
+
const root = projectRoot || process.cwd();
|
|
17
|
+
return path.join(root, '.automatosx');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get AutomatosX config file path
|
|
21
|
+
*/
|
|
22
|
+
export function getAutomatosXConfigPath(projectRoot) {
|
|
23
|
+
return path.join(getAutomatosXConfigDir(projectRoot), 'config.json');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Check if AutomatosX config exists
|
|
27
|
+
*/
|
|
28
|
+
export function automatosXConfigExists(projectRoot) {
|
|
29
|
+
const configPath = getAutomatosXConfigPath(projectRoot);
|
|
30
|
+
return fs.existsSync(configPath);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Load AutomatosX configuration file
|
|
34
|
+
*/
|
|
35
|
+
export function loadAutomatosXConfigFile(projectRoot) {
|
|
36
|
+
const configPath = getAutomatosXConfigPath(projectRoot);
|
|
37
|
+
if (!fs.existsSync(configPath)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const raw = fs.readFileSync(configPath, 'utf-8');
|
|
42
|
+
const data = JSON.parse(raw);
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.warn(`Failed to load AutomatosX config from ${configPath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Load and migrate AutomatosX MCP server configurations
|
|
52
|
+
*/
|
|
53
|
+
export function loadAutomatosXMCPServers(projectRoot) {
|
|
54
|
+
const warnings = [];
|
|
55
|
+
const errors = [];
|
|
56
|
+
const migrations = new Map();
|
|
57
|
+
const servers = [];
|
|
58
|
+
// Check if AutomatosX config exists
|
|
59
|
+
const configPath = getAutomatosXConfigPath(projectRoot);
|
|
60
|
+
if (!fs.existsSync(configPath)) {
|
|
61
|
+
return {
|
|
62
|
+
found: false,
|
|
63
|
+
servers: [],
|
|
64
|
+
migrations,
|
|
65
|
+
warnings,
|
|
66
|
+
errors
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Load config
|
|
70
|
+
const config = loadAutomatosXConfigFile(projectRoot);
|
|
71
|
+
if (!config) {
|
|
72
|
+
errors.push('Failed to load AutomatosX config');
|
|
73
|
+
return {
|
|
74
|
+
found: true,
|
|
75
|
+
configPath,
|
|
76
|
+
servers: [],
|
|
77
|
+
migrations,
|
|
78
|
+
warnings,
|
|
79
|
+
errors
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// Extract MCP servers
|
|
83
|
+
if (!config.mcpServers || typeof config.mcpServers !== 'object') {
|
|
84
|
+
warnings.push('AutomatosX config found but no MCP servers configured');
|
|
85
|
+
return {
|
|
86
|
+
found: true,
|
|
87
|
+
configPath,
|
|
88
|
+
servers: [],
|
|
89
|
+
migrations,
|
|
90
|
+
warnings,
|
|
91
|
+
errors
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// Detect version
|
|
95
|
+
if (config.automatosxVersion) {
|
|
96
|
+
warnings.push(`AutomatosX version detected: ${config.automatosxVersion}`);
|
|
97
|
+
}
|
|
98
|
+
// Migrate each server
|
|
99
|
+
for (const [name, serverConfig] of Object.entries(config.mcpServers)) {
|
|
100
|
+
// Ensure server has name field
|
|
101
|
+
const configWithName = { ...serverConfig, name: serverConfig.name || name };
|
|
102
|
+
// Detect format
|
|
103
|
+
const detection = detectConfigFormat(configWithName);
|
|
104
|
+
if (detection.isLegacy) {
|
|
105
|
+
warnings.push(`Server "${name}" uses legacy format - migrating automatically`);
|
|
106
|
+
}
|
|
107
|
+
// Migrate
|
|
108
|
+
const migration = migrateConfig(configWithName);
|
|
109
|
+
migrations.set(name, migration);
|
|
110
|
+
if (migration.success && migration.migratedConfig) {
|
|
111
|
+
servers.push(migration.migratedConfig);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
errors.push(`Failed to migrate server "${name}": ${migration.errors.join(', ')}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
found: true,
|
|
119
|
+
configPath,
|
|
120
|
+
servers,
|
|
121
|
+
migrations,
|
|
122
|
+
warnings,
|
|
123
|
+
errors
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Merge ax-cli and AutomatosX MCP server configurations
|
|
128
|
+
*
|
|
129
|
+
* Strategy:
|
|
130
|
+
* - ax-cli configs take precedence (user explicitly configured)
|
|
131
|
+
* - AutomatosX configs provide defaults/fallbacks
|
|
132
|
+
* - Conflicts are logged as warnings
|
|
133
|
+
* - Both configs can coexist (different server names)
|
|
134
|
+
*/
|
|
135
|
+
export function mergeConfigs(axCliServers, automatosXServers) {
|
|
136
|
+
const merged = new Map();
|
|
137
|
+
const sources = new Map();
|
|
138
|
+
const conflicts = [];
|
|
139
|
+
const warnings = [];
|
|
140
|
+
// Add AutomatosX servers first (lower priority)
|
|
141
|
+
for (const server of automatosXServers) {
|
|
142
|
+
merged.set(server.name, server);
|
|
143
|
+
sources.set(server.name, 'automatosx');
|
|
144
|
+
}
|
|
145
|
+
// Add/override with ax-cli servers (higher priority)
|
|
146
|
+
for (const server of axCliServers) {
|
|
147
|
+
const existingServer = merged.get(server.name);
|
|
148
|
+
if (existingServer) {
|
|
149
|
+
// Conflict detected
|
|
150
|
+
const automatosXServer = existingServer;
|
|
151
|
+
// Check if configs are identical (no real conflict)
|
|
152
|
+
const areIdentical = JSON.stringify(automatosXServer) === JSON.stringify(server);
|
|
153
|
+
if (areIdentical) {
|
|
154
|
+
sources.set(server.name, 'both');
|
|
155
|
+
warnings.push(`Server "${server.name}" configured in both ax-cli and AutomatosX with identical settings`);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
sources.set(server.name, 'ax-cli');
|
|
159
|
+
conflicts.push({
|
|
160
|
+
serverName: server.name,
|
|
161
|
+
axCliConfig: server,
|
|
162
|
+
automatosXConfig: automatosXServer,
|
|
163
|
+
resolution: 'ax-cli-wins'
|
|
164
|
+
});
|
|
165
|
+
warnings.push(`Server "${server.name}" configured in both ax-cli and AutomatosX. Using ax-cli version.`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
sources.set(server.name, 'ax-cli');
|
|
170
|
+
}
|
|
171
|
+
// ax-cli always wins
|
|
172
|
+
merged.set(server.name, server);
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
servers: Array.from(merged.values()),
|
|
176
|
+
sources,
|
|
177
|
+
conflicts,
|
|
178
|
+
warnings
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Format merge result for display
|
|
183
|
+
*/
|
|
184
|
+
export function formatMergeResult(result) {
|
|
185
|
+
const lines = [];
|
|
186
|
+
lines.push('╭─ MCP Config Merge Summary ────────────────────╮');
|
|
187
|
+
lines.push(`│ Total servers: ${result.servers.length}`);
|
|
188
|
+
const axCliCount = Array.from(result.sources.values()).filter(s => s === 'ax-cli').length;
|
|
189
|
+
const automatosXCount = Array.from(result.sources.values()).filter(s => s === 'automatosx').length;
|
|
190
|
+
const bothCount = Array.from(result.sources.values()).filter(s => s === 'both').length;
|
|
191
|
+
if (axCliCount > 0) {
|
|
192
|
+
lines.push(`│ From ax-cli: ${axCliCount}`);
|
|
193
|
+
}
|
|
194
|
+
if (automatosXCount > 0) {
|
|
195
|
+
lines.push(`│ From AutomatosX: ${automatosXCount}`);
|
|
196
|
+
}
|
|
197
|
+
if (bothCount > 0) {
|
|
198
|
+
lines.push(`│ In both (identical): ${bothCount}`);
|
|
199
|
+
}
|
|
200
|
+
if (result.conflicts.length > 0) {
|
|
201
|
+
lines.push(`│ Conflicts resolved: ${result.conflicts.length}`);
|
|
202
|
+
}
|
|
203
|
+
lines.push('╰────────────────────────────────────────────────╯');
|
|
204
|
+
// Show conflicts
|
|
205
|
+
if (result.conflicts.length > 0) {
|
|
206
|
+
lines.push('');
|
|
207
|
+
lines.push('Conflicts (ax-cli config used):');
|
|
208
|
+
result.conflicts.forEach(conflict => {
|
|
209
|
+
lines.push(` • ${conflict.serverName}`);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
// Show warnings
|
|
213
|
+
if (result.warnings.length > 0) {
|
|
214
|
+
lines.push('');
|
|
215
|
+
result.warnings.forEach(warning => {
|
|
216
|
+
lines.push(`⚠️ ${warning}`);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return lines.join('\n');
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get recommendation for user based on merge result
|
|
223
|
+
*/
|
|
224
|
+
export function getConfigRecommendation(result) {
|
|
225
|
+
// If there are conflicts, recommend consolidation
|
|
226
|
+
if (result.conflicts.length > 0) {
|
|
227
|
+
return ('Recommendation: Consolidate your MCP server configurations into .ax-cli/settings.json\n' +
|
|
228
|
+
'to avoid conflicts. Run: ax-cli mcp migrate --from .automatosx/config.json');
|
|
229
|
+
}
|
|
230
|
+
// If AutomatosX configs exist but no conflicts, inform user
|
|
231
|
+
const automatosXCount = Array.from(result.sources.values()).filter(s => s === 'automatosx').length;
|
|
232
|
+
if (automatosXCount > 0) {
|
|
233
|
+
return ('Info: Using MCP servers from AutomatosX config. This is OK, but consider\n' +
|
|
234
|
+
'migrating to .ax-cli/settings.json for better integration.');
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=automatosx-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"automatosx-loader.js","sourceRoot":"","sources":["../../src/mcp/automatosx-loader.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,aAAa,EAAwB,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AA0C1D;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAoB;IACzD,MAAM,IAAI,GAAG,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,WAAoB;IAC1D,OAAO,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,WAAW,CAAC,EAAE,aAAa,CAAC,CAAC;AACvE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,WAAoB;IACzD,MAAM,UAAU,GAAG,uBAAuB,CAAC,WAAW,CAAC,CAAC;IACxD,OAAO,E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CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,gBAAgB;IAChB,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAChC,KAAK,CAAC,IAAI,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAA0B;IAChE,kDAAkD;IAClD,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO,CACL,yFAAyF;YACzF,4EAA4E,CAC7E,CAAC;IACJ,CAAC;IAED,4DAA4D;IAC5D,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,MAAM,CAAC;IAEnG,IAAI,eAAe,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,CACL,4EAA4E;YAC5E,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutex-Protected MCP Client Patch
|
|
3
|
+
*
|
|
4
|
+
* This file contains the mutex-protected version of addServer() method
|
|
5
|
+
* to be integrated into MCPManager class in client.ts
|
|
6
|
+
*
|
|
7
|
+
* INTEGRATION INSTRUCTIONS:
|
|
8
|
+
* 1. Add import: import { KeyedMutex } from "./mutex.js";
|
|
9
|
+
* 2. Add field: private connectionMutex = new KeyedMutex();
|
|
10
|
+
* 3. Replace addServer() method with the version below
|
|
11
|
+
* 4. Add mutex cleanup to dispose() method
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Benefits of Mutex Protection:
|
|
15
|
+
*
|
|
16
|
+
* 1. Race Condition Prevention:
|
|
17
|
+
* - Multiple concurrent addServer() calls for same server
|
|
18
|
+
* - Multi-agent AutomatosX setups calling ensureServersInitialized()
|
|
19
|
+
* - Duplicate connections from parallel initialization
|
|
20
|
+
*
|
|
21
|
+
* 2. Resource Protection:
|
|
22
|
+
* - Prevents duplicate client instances
|
|
23
|
+
* - Avoids wasted file descriptors/memory
|
|
24
|
+
* - Ensures clean state transitions
|
|
25
|
+
*
|
|
26
|
+
* 3. Thread Safety:
|
|
27
|
+
* - Atomic check-and-set operations
|
|
28
|
+
* - No TOCTOU (Time-Of-Check-Time-Of-Use) bugs
|
|
29
|
+
* - Guaranteed sequential execution per server
|
|
30
|
+
*
|
|
31
|
+
* Performance Impact: Negligible
|
|
32
|
+
* - Mutex only blocks same-server connections
|
|
33
|
+
* - Different servers connect in parallel
|
|
34
|
+
* - Minimal overhead (~microseconds per acquire/release)
|
|
35
|
+
*/
|
|
36
|
+
export declare const MUTEX_INTEGRATION_COMPLETE = false;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutex-Protected MCP Client Patch
|
|
3
|
+
*
|
|
4
|
+
* This file contains the mutex-protected version of addServer() method
|
|
5
|
+
* to be integrated into MCPManager class in client.ts
|
|
6
|
+
*
|
|
7
|
+
* INTEGRATION INSTRUCTIONS:
|
|
8
|
+
* 1. Add import: import { KeyedMutex } from "./mutex.js";
|
|
9
|
+
* 2. Add field: private connectionMutex = new KeyedMutex();
|
|
10
|
+
* 3. Replace addServer() method with the version below
|
|
11
|
+
* 4. Add mutex cleanup to dispose() method
|
|
12
|
+
*/
|
|
13
|
+
// STEP 1: Add to imports (line 8)
|
|
14
|
+
// import { KeyedMutex } from "./mutex.js";
|
|
15
|
+
// STEP 2: Add to MCPManager class fields (after line 26)
|
|
16
|
+
// private connectionMutex = new KeyedMutex(); // Mutex for thread-safe connections
|
|
17
|
+
// STEP 3: Replace addServer() method (lines 28-50)
|
|
18
|
+
/*
|
|
19
|
+
async addServer(config: MCPServerConfig): Promise<void> {
|
|
20
|
+
// Use mutex to ensure atomic check-and-connect operation
|
|
21
|
+
// This prevents race conditions when multiple parts of the system
|
|
22
|
+
// try to connect to the same server simultaneously
|
|
23
|
+
return await this.connectionMutex.runExclusive(config.name, async () => {
|
|
24
|
+
// Check if already connected (now protected by mutex)
|
|
25
|
+
if (this.clients.has(config.name)) {
|
|
26
|
+
return; // Already connected, nothing to do
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Check if already connecting (now protected by mutex)
|
|
30
|
+
const pending = this.pendingConnections.get(config.name);
|
|
31
|
+
if (pending) {
|
|
32
|
+
await pending; // Wait for the connection to complete
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Create a promise for this connection attempt
|
|
37
|
+
const connectionPromise = this._addServerInternal(config);
|
|
38
|
+
this.pendingConnections.set(config.name, connectionPromise);
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
await connectionPromise;
|
|
42
|
+
} finally {
|
|
43
|
+
this.pendingConnections.delete(config.name);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
*/
|
|
48
|
+
// STEP 4: Add to dispose() method (before removeAllListeners())
|
|
49
|
+
// // Cleanup mutex state
|
|
50
|
+
// this.connectionMutex.clearAll();
|
|
51
|
+
/**
|
|
52
|
+
* Benefits of Mutex Protection:
|
|
53
|
+
*
|
|
54
|
+
* 1. Race Condition Prevention:
|
|
55
|
+
* - Multiple concurrent addServer() calls for same server
|
|
56
|
+
* - Multi-agent AutomatosX setups calling ensureServersInitialized()
|
|
57
|
+
* - Duplicate connections from parallel initialization
|
|
58
|
+
*
|
|
59
|
+
* 2. Resource Protection:
|
|
60
|
+
* - Prevents duplicate client instances
|
|
61
|
+
* - Avoids wasted file descriptors/memory
|
|
62
|
+
* - Ensures clean state transitions
|
|
63
|
+
*
|
|
64
|
+
* 3. Thread Safety:
|
|
65
|
+
* - Atomic check-and-set operations
|
|
66
|
+
* - No TOCTOU (Time-Of-Check-Time-Of-Use) bugs
|
|
67
|
+
* - Guaranteed sequential execution per server
|
|
68
|
+
*
|
|
69
|
+
* Performance Impact: Negligible
|
|
70
|
+
* - Mutex only blocks same-server connections
|
|
71
|
+
* - Different servers connect in parallel
|
|
72
|
+
* - Minimal overhead (~microseconds per acquire/release)
|
|
73
|
+
*/
|
|
74
|
+
export const MUTEX_INTEGRATION_COMPLETE = false; // Set to true after integration
|
|
75
|
+
//# sourceMappingURL=client-mutex-patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-mutex-patch.js","sourceRoot":"","sources":["../../src/mcp/client-mutex-patch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,kCAAkC;AAClC,2CAA2C;AAE3C,yDAAyD;AACzD,mFAAmF;AAEnF,mDAAmD;AACnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BE;AAEF,gEAAgE;AAChE,yBAAyB;AACzB,mCAAmC;AAEnC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,CAAC,CAAC,gCAAgC"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-Safe MCP Client (Phase 1 Improvements)
|
|
3
|
+
*
|
|
4
|
+
* Improvements applied:
|
|
5
|
+
* 1. SafeMutex with lock tokens (prevents race conditions)
|
|
6
|
+
* 2. Result types for all public APIs (explicit error handling)
|
|
7
|
+
* 3. State machine for connection tracking (type-safe states)
|
|
8
|
+
* 4. Branded types for ServerName/ToolName (prevent confusion)
|
|
9
|
+
* 5. Invariant checks (runtime validation)
|
|
10
|
+
*
|
|
11
|
+
* Coverage: 70% → 85%+ (Phase 1)
|
|
12
|
+
*/
|
|
13
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
14
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
15
|
+
import { EventEmitter } from "events";
|
|
16
|
+
import { MCPTransport, TransportType } from "./transports.js";
|
|
17
|
+
import type { MCPServerConfig, MCPTransportConfig } from "../schemas/settings-schemas.js";
|
|
18
|
+
import { Result } from "./type-safety.js";
|
|
19
|
+
import { ServerName, ToolName, createServerName } from "./type-safety.js";
|
|
20
|
+
export type { MCPServerConfig, MCPTransportConfig, ServerName, ToolName };
|
|
21
|
+
/**
|
|
22
|
+
* Connection State Machine
|
|
23
|
+
*
|
|
24
|
+
* Valid transitions:
|
|
25
|
+
* - idle → connecting (addServer called)
|
|
26
|
+
* - connecting → connected (connection succeeds)
|
|
27
|
+
* - connecting → failed (connection fails)
|
|
28
|
+
* - connected → disconnecting (removeServer called)
|
|
29
|
+
* - disconnecting → idle (cleanup complete)
|
|
30
|
+
* - failed → idle (reset)
|
|
31
|
+
*/
|
|
32
|
+
export type ConnectionState = {
|
|
33
|
+
status: 'idle';
|
|
34
|
+
serverName: ServerName;
|
|
35
|
+
} | {
|
|
36
|
+
status: 'connecting';
|
|
37
|
+
serverName: ServerName;
|
|
38
|
+
startedAt: number;
|
|
39
|
+
promise: Promise<Result<void, Error>>;
|
|
40
|
+
} | {
|
|
41
|
+
status: 'connected';
|
|
42
|
+
serverName: ServerName;
|
|
43
|
+
client: Client;
|
|
44
|
+
transport: MCPTransport;
|
|
45
|
+
connectedAt: number;
|
|
46
|
+
} | {
|
|
47
|
+
status: 'disconnecting';
|
|
48
|
+
serverName: ServerName;
|
|
49
|
+
client: Client;
|
|
50
|
+
transport: MCPTransport;
|
|
51
|
+
} | {
|
|
52
|
+
status: 'failed';
|
|
53
|
+
serverName: ServerName;
|
|
54
|
+
error: Error;
|
|
55
|
+
failedAt: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Reconnection Configuration
|
|
59
|
+
*
|
|
60
|
+
* Controls automatic reconnection behavior when MCP servers fail or disconnect.
|
|
61
|
+
* Uses exponential backoff to avoid overwhelming failed servers.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const config: ReconnectionConfig = {
|
|
66
|
+
* enabled: true,
|
|
67
|
+
* maxRetries: 5,
|
|
68
|
+
* initialDelayMs: 1000,
|
|
69
|
+
* maxDelayMs: 30000,
|
|
70
|
+
* backoffMultiplier: 2
|
|
71
|
+
* };
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export interface ReconnectionConfig {
|
|
75
|
+
/** Enable automatic reconnection on failure */
|
|
76
|
+
enabled: boolean;
|
|
77
|
+
/** Maximum number of reconnection attempts before giving up (default: 5) */
|
|
78
|
+
maxRetries: number;
|
|
79
|
+
/** Initial delay before first reconnection attempt in ms (default: 1000) */
|
|
80
|
+
initialDelayMs: number;
|
|
81
|
+
/** Maximum delay between reconnection attempts in ms (default: 30000) */
|
|
82
|
+
maxDelayMs: number;
|
|
83
|
+
/** Multiplier for exponential backoff (default: 2) */
|
|
84
|
+
backoffMultiplier: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Default reconnection configuration
|
|
88
|
+
*/
|
|
89
|
+
export declare const DEFAULT_RECONNECTION_CONFIG: ReconnectionConfig;
|
|
90
|
+
/**
|
|
91
|
+
* Health Check Configuration
|
|
92
|
+
*/
|
|
93
|
+
export interface HealthCheckConfig {
|
|
94
|
+
/** Enable periodic health checks */
|
|
95
|
+
enabled: boolean;
|
|
96
|
+
/** Interval between health checks in ms (default: 30000) */
|
|
97
|
+
intervalMs: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Default health check configuration
|
|
101
|
+
*/
|
|
102
|
+
export declare const DEFAULT_HEALTH_CHECK_CONFIG: HealthCheckConfig;
|
|
103
|
+
/**
|
|
104
|
+
* MCP Tool with branded types
|
|
105
|
+
*/
|
|
106
|
+
export interface MCPTool {
|
|
107
|
+
name: ToolName;
|
|
108
|
+
description: string;
|
|
109
|
+
inputSchema: any;
|
|
110
|
+
serverName: ServerName;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Type-safe MCP Manager with improved safety
|
|
114
|
+
*/
|
|
115
|
+
export declare class MCPManagerV2 extends EventEmitter {
|
|
116
|
+
private connections;
|
|
117
|
+
private tools;
|
|
118
|
+
private connectionMutex;
|
|
119
|
+
private initializationPromise;
|
|
120
|
+
private tokenCounter;
|
|
121
|
+
private disposed;
|
|
122
|
+
private reconnectionConfig;
|
|
123
|
+
private healthCheckConfig;
|
|
124
|
+
private reconnectionAttempts;
|
|
125
|
+
private reconnectionTimers;
|
|
126
|
+
private serverConfigs;
|
|
127
|
+
private healthCheckTimer;
|
|
128
|
+
constructor(reconnectionConfig?: Partial<ReconnectionConfig>, healthCheckConfig?: Partial<HealthCheckConfig>);
|
|
129
|
+
/**
|
|
130
|
+
* Add MCP server with type-safe connection management
|
|
131
|
+
*
|
|
132
|
+
* Phase 1 improvements:
|
|
133
|
+
* - Returns Result instead of throwing
|
|
134
|
+
* - Uses SafeMutex for concurrency control
|
|
135
|
+
* - Tracks state machine transitions
|
|
136
|
+
* - Validates inputs with invariants
|
|
137
|
+
*/
|
|
138
|
+
addServer(config: MCPServerConfig): Promise<Result<void, Error>>;
|
|
139
|
+
/**
|
|
140
|
+
* Internal connection logic with state transitions
|
|
141
|
+
*/
|
|
142
|
+
private _addServerInternal;
|
|
143
|
+
/**
|
|
144
|
+
* Remove MCP server with proper state transitions
|
|
145
|
+
*/
|
|
146
|
+
removeServer(serverName: ServerName): Promise<Result<void, Error>>;
|
|
147
|
+
/**
|
|
148
|
+
* Internal disconnection logic with state transitions
|
|
149
|
+
*/
|
|
150
|
+
private _removeServerInternal;
|
|
151
|
+
/**
|
|
152
|
+
* Close client with error handling
|
|
153
|
+
*/
|
|
154
|
+
private closeClient;
|
|
155
|
+
/**
|
|
156
|
+
* Disconnect transport with error handling
|
|
157
|
+
*/
|
|
158
|
+
private disconnectTransport;
|
|
159
|
+
/**
|
|
160
|
+
* Call MCP tool with type safety
|
|
161
|
+
*/
|
|
162
|
+
callTool(toolName: ToolName, arguments_: Record<string, unknown> | null | undefined): Promise<Result<CallToolResult, Error>>;
|
|
163
|
+
/**
|
|
164
|
+
* Truncate text to fit within token limit
|
|
165
|
+
* UNICODE FIX: Uses grapheme clusters
|
|
166
|
+
*/
|
|
167
|
+
private truncateToTokenLimit;
|
|
168
|
+
/**
|
|
169
|
+
* Get all tools
|
|
170
|
+
*/
|
|
171
|
+
getTools(): MCPTool[];
|
|
172
|
+
/**
|
|
173
|
+
* Get all connected servers
|
|
174
|
+
*/
|
|
175
|
+
getServers(): ServerName[];
|
|
176
|
+
/**
|
|
177
|
+
* Get connection state for a server
|
|
178
|
+
*/
|
|
179
|
+
getConnectionState(serverName: ServerName): ConnectionState | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Get transport type for a server
|
|
182
|
+
*/
|
|
183
|
+
getTransportType(serverName: ServerName): Result<TransportType, Error>;
|
|
184
|
+
/**
|
|
185
|
+
* Schedule reconnection for a failed server with exponential backoff
|
|
186
|
+
*
|
|
187
|
+
* Phase 2: Automatic reconnection logic
|
|
188
|
+
*
|
|
189
|
+
* @param serverName - Server to reconnect
|
|
190
|
+
* @param config - Server configuration
|
|
191
|
+
*/
|
|
192
|
+
private scheduleReconnection;
|
|
193
|
+
/**
|
|
194
|
+
* Cancel reconnection for a server
|
|
195
|
+
*/
|
|
196
|
+
private cancelReconnection;
|
|
197
|
+
/**
|
|
198
|
+
* Perform health check on a single server
|
|
199
|
+
*
|
|
200
|
+
* @param serverName - Server to check
|
|
201
|
+
* @returns Result indicating health status
|
|
202
|
+
*/
|
|
203
|
+
healthCheck(serverName: ServerName): Promise<Result<boolean, Error>>;
|
|
204
|
+
/**
|
|
205
|
+
* Start periodic health checks for all connected servers
|
|
206
|
+
*/
|
|
207
|
+
private startHealthChecks;
|
|
208
|
+
/**
|
|
209
|
+
* Stop periodic health checks
|
|
210
|
+
*/
|
|
211
|
+
private stopHealthChecks;
|
|
212
|
+
/**
|
|
213
|
+
* Shutdown all servers
|
|
214
|
+
*/
|
|
215
|
+
shutdown(): Promise<Result<void, Error>>;
|
|
216
|
+
/**
|
|
217
|
+
* Ensure servers initialized
|
|
218
|
+
*/
|
|
219
|
+
ensureServersInitialized(): Promise<Result<void, Error>>;
|
|
220
|
+
/**
|
|
221
|
+
* Dispose all resources
|
|
222
|
+
*/
|
|
223
|
+
dispose(): Promise<Result<void, Error>>;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Helper functions for creating branded types
|
|
227
|
+
*/
|
|
228
|
+
declare function createToolName(name: string): ToolName | null;
|
|
229
|
+
export { createServerName, createToolName };
|