@defai.digital/ax-cli 4.3.5 → 4.3.8
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 +113 -36
- package/dist/agent/execution/tool-executor.js +1 -1
- package/dist/agent/execution/tool-executor.js.map +1 -1
- package/dist/agent/llm-agent.js +2 -2
- package/dist/agent/llm-agent.js.map +1 -1
- package/dist/agent/subagent-types.js +15 -14
- package/dist/agent/subagent-types.js.map +1 -1
- package/dist/checkpoint/manager.js +10 -5
- package/dist/checkpoint/manager.js.map +1 -1
- package/dist/checkpoint/storage.js.map +1 -1
- package/dist/checkpoint/types.d.ts +1 -1
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init/wizard.js +4 -4
- package/dist/commands/init/wizard.js.map +1 -1
- package/dist/commands/init.js +2 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/mcp.js +7 -2
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/memory.js +15 -14
- package/dist/commands/memory.js.map +1 -1
- package/dist/commands/models.js +67 -22
- package/dist/commands/models.js.map +1 -1
- package/dist/commands/plan.js +18 -32
- package/dist/commands/plan.js.map +1 -1
- package/dist/commands/setup.js +5 -5
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/status.js +11 -7
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/templates.js +10 -9
- package/dist/commands/templates.js.map +1 -1
- package/dist/commands/update.js +30 -28
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/usage.js +133 -14
- package/dist/commands/usage.js.map +1 -1
- package/dist/constants.d.ts +17 -0
- package/dist/constants.js +21 -0
- package/dist/constants.js.map +1 -1
- package/dist/hooks/manager.js +4 -0
- package/dist/hooks/manager.js.map +1 -1
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/llm/client.d.ts +11 -1
- package/dist/llm/client.js +48 -19
- package/dist/llm/client.js.map +1 -1
- package/dist/llm/tools.js +7 -6
- package/dist/llm/tools.js.map +1 -1
- package/dist/llm/types.d.ts +34 -10
- package/dist/llm/types.js +8 -1
- package/dist/llm/types.js.map +1 -1
- package/dist/mcp/automatosx-loader.d.ts +4 -4
- package/dist/mcp/automatosx-loader.js +2 -1
- package/dist/mcp/automatosx-loader.js.map +1 -1
- package/dist/mcp/client-v2.d.ts +4 -2
- package/dist/mcp/client-v2.js +30 -16
- package/dist/mcp/client-v2.js.map +1 -1
- package/dist/mcp/client.d.ts +2 -2
- package/dist/mcp/config-detector.d.ts +6 -6
- package/dist/mcp/config-detector.js +25 -20
- package/dist/mcp/config-detector.js.map +1 -1
- package/dist/mcp/config-migrator.d.ts +6 -6
- package/dist/mcp/config-migrator.js +14 -12
- package/dist/mcp/config-migrator.js.map +1 -1
- package/dist/mcp/error-formatter.d.ts +1 -1
- package/dist/mcp/error-formatter.js.map +1 -1
- package/dist/mcp/health.js.map +1 -1
- package/dist/mcp/invariants.d.ts +1 -1
- package/dist/mcp/invariants.js.map +1 -1
- package/dist/mcp/reconnection.js +41 -38
- package/dist/mcp/reconnection.js.map +1 -1
- package/dist/mcp/registry.js.map +1 -1
- package/dist/mcp/type-safety.d.ts +4 -15
- package/dist/mcp/type-safety.js +0 -12
- package/dist/mcp/type-safety.js.map +1 -1
- package/dist/memory/context-generator.js +19 -9
- package/dist/memory/context-generator.js.map +1 -1
- package/dist/planner/plan-storage.js +22 -29
- package/dist/planner/plan-storage.js.map +1 -1
- package/dist/provider/config.d.ts +58 -0
- package/dist/provider/config.js +180 -7
- package/dist/provider/config.js.map +1 -1
- package/dist/schemas/yaml-schemas.d.ts +34 -0
- package/dist/schemas/yaml-schemas.js +34 -0
- package/dist/schemas/yaml-schemas.js.map +1 -1
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/testing.d.ts +16 -18
- package/dist/sdk/testing.js +0 -22
- package/dist/sdk/testing.js.map +1 -1
- package/dist/tools/ax-agent.js +4 -0
- package/dist/tools/ax-agent.js.map +1 -1
- package/dist/tools/priority-registry.d.ts +124 -0
- package/dist/tools/priority-registry.js +401 -0
- package/dist/tools/priority-registry.js.map +1 -0
- package/dist/tools/priority.d.ts +158 -0
- package/dist/tools/priority.js +350 -0
- package/dist/tools/priority.js.map +1 -0
- package/dist/ui/components/api-key-input.js +1 -1
- package/dist/ui/components/api-key-input.js.map +1 -1
- package/dist/ui/components/chat-interface.js +2 -2
- package/dist/ui/components/chat-interface.js.map +1 -1
- package/dist/ui/components/mcp-dashboard.js +3 -3
- package/dist/ui/components/mcp-dashboard.js.map +1 -1
- package/dist/ui/hooks/use-input-handler.js +2 -2
- package/dist/ui/hooks/use-input-handler.js.map +1 -1
- package/dist/utils/config-loader.d.ts +17 -0
- package/dist/utils/config-loader.js.map +1 -1
- package/dist/utils/history-manager.js +7 -5
- package/dist/utils/history-manager.js.map +1 -1
- package/dist/utils/process-pool.js +1 -1
- package/dist/utils/process-pool.js.map +1 -1
- package/dist/utils/settings-manager.js +4 -1
- package/dist/utils/settings-manager.js.map +1 -1
- package/package.json +11 -3
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Priority Registry - Tool Selection Engine
|
|
3
|
+
*
|
|
4
|
+
* Manages priority-based tool selection to ensure the right tool is used for each task.
|
|
5
|
+
* Prevents AutomatosX MCP from overshadowing native capabilities or provider-specific MCPs.
|
|
6
|
+
*
|
|
7
|
+
* Key behaviors:
|
|
8
|
+
* - Grok web search → Uses native API (not AutomatosX MCP)
|
|
9
|
+
* - GLM web search → Uses Z.AI MCP (not AutomatosX MCP)
|
|
10
|
+
* - Figma tasks → Uses Figma MCP regardless of provider
|
|
11
|
+
* - Memory/agent delegation → Uses AutomatosX MCP (its primary purpose)
|
|
12
|
+
*/
|
|
13
|
+
import { getActiveProvider } from '../provider/config.js';
|
|
14
|
+
import { ToolPriority, SUPERSEDE_THRESHOLD, NATIVE_CAPABILITY_PREFIX, isVariantOf, hasNativeCapability, getServerCapabilityMapping, getServerPriority, providerMatches, } from './priority.js';
|
|
15
|
+
/**
|
|
16
|
+
* Prefix for MCP tool names.
|
|
17
|
+
* e.g., 'mcp__automatosx__run_agent' starts with 'mcp__'
|
|
18
|
+
*/
|
|
19
|
+
const MCP_TOOL_PREFIX = 'mcp__';
|
|
20
|
+
/**
|
|
21
|
+
* Separator used in MCP tool names between prefix, server name, and tool name.
|
|
22
|
+
*/
|
|
23
|
+
const MCP_NAME_SEPARATOR = '__';
|
|
24
|
+
/**
|
|
25
|
+
* Well-known MCP server names used in capability guidance.
|
|
26
|
+
* These are referenced when providing context-aware tool recommendations.
|
|
27
|
+
*/
|
|
28
|
+
const KNOWN_SERVERS = {
|
|
29
|
+
ZAI_WEB_SEARCH: 'zai-web-search',
|
|
30
|
+
AUTOMATOSX: 'automatosx',
|
|
31
|
+
FIGMA: 'figma',
|
|
32
|
+
GITHUB: 'github',
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Extract server name from MCP tool name
|
|
36
|
+
* e.g., 'mcp__automatosx__run_agent' → 'automatosx'
|
|
37
|
+
*
|
|
38
|
+
* ASSUMPTION: Server names do NOT contain "__" (double underscore).
|
|
39
|
+
* This is enforced by MCPServerIdSchema in @defai.digital/ax-schemas.
|
|
40
|
+
* If server names could contain "__", this parsing would fail.
|
|
41
|
+
*
|
|
42
|
+
* Returns undefined for:
|
|
43
|
+
* - Non-MCP tools (don't start with MCP_TOOL_PREFIX)
|
|
44
|
+
* - Malformed MCP tools with empty server name (e.g., 'mcp__' or 'mcp____tool')
|
|
45
|
+
*/
|
|
46
|
+
export function extractServerNameFromTool(toolName) {
|
|
47
|
+
if (!toolName.startsWith(MCP_TOOL_PREFIX)) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
// Format: mcp__serverName__toolName - server name is at index 1
|
|
51
|
+
// Note: This assumes server names don't contain "__" (enforced by MCPServerIdSchema)
|
|
52
|
+
const parts = toolName.split(MCP_NAME_SEPARATOR);
|
|
53
|
+
// BUG FIX: Validate that tool name has correct format (at least 3 parts: 'mcp', serverName, toolName)
|
|
54
|
+
// Malformed names like 'mcp__' or 'mcp____tool' would return empty/undefined server names
|
|
55
|
+
if (parts.length < 3 || !parts[1]) {
|
|
56
|
+
// Only log in debug mode to avoid console spam
|
|
57
|
+
if (process.env.DEBUG || process.env.AX_DEBUG) {
|
|
58
|
+
console.warn(`Malformed MCP tool name: "${toolName}". Expected format: mcp__serverName__toolName`);
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
return parts[1];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Helper to check if any phrase is found in text
|
|
66
|
+
*/
|
|
67
|
+
function containsAny(text, phrases) {
|
|
68
|
+
return phrases.some(phrase => text.includes(phrase));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if a server name matches a target (case-insensitive, supports variants)
|
|
72
|
+
*/
|
|
73
|
+
function serverNameMatches(serverName, target) {
|
|
74
|
+
const normalizedServer = serverName.toLowerCase();
|
|
75
|
+
const normalizedTarget = target.toLowerCase();
|
|
76
|
+
return normalizedServer === normalizedTarget || isVariantOf(normalizedServer, normalizedTarget);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Capability detection rules - defines how to detect each capability
|
|
80
|
+
*/
|
|
81
|
+
const CAPABILITY_RULES = [
|
|
82
|
+
// Web search - exclude file search tools
|
|
83
|
+
{
|
|
84
|
+
capability: 'web-search',
|
|
85
|
+
nameIncludes: ['websearch', 'web_search'],
|
|
86
|
+
descIncludes: ['search the web', 'on the web', 'web search', 'internet search'],
|
|
87
|
+
excludeNamePattern: /\bfile\b|_file\b|\bfile_|\bgrep\b|_grep\b|\bgrep_|\bglob\b|_glob\b|\bglob_/,
|
|
88
|
+
excludeDescIncludes: ['search files', 'file search'],
|
|
89
|
+
},
|
|
90
|
+
// Web fetch - exclude file readers
|
|
91
|
+
{
|
|
92
|
+
capability: 'web-fetch',
|
|
93
|
+
nameIncludes: ['webfetch', 'web_fetch', 'url_fetch', 'web-reader', 'web_reader'],
|
|
94
|
+
descIncludes: ['fetch url', 'fetch content from url', 'fetch web', 'http request'],
|
|
95
|
+
excludeNamePattern: /\bpdf\b|_pdf\b|\bpdf_|\bcsv\b|_csv\b|\bcsv_|\bfile\b|_file\b|\bfile_/,
|
|
96
|
+
excludeDescIncludes: ['read file', 'parse file'],
|
|
97
|
+
},
|
|
98
|
+
// Vision - exclude image manipulation tools
|
|
99
|
+
{
|
|
100
|
+
capability: 'vision',
|
|
101
|
+
namePatterns: /\bvision\b|\bcomputer vision\b|\bmachine vision\b/,
|
|
102
|
+
descPatterns: /\bvision\b|\bcomputer vision\b|\bmachine vision\b/,
|
|
103
|
+
descIncludes: ['image analysis', 'image understanding', 'analyze image', 'visual understanding'],
|
|
104
|
+
excludeNamePattern: /\bresize_image\b|\bget_image_dimensions\b|\bcompress_image\b|\bconvert_image_format\b|\bimage_resize\b|\bimage_compress\b|\bimage_convert\b/,
|
|
105
|
+
excludeDescIncludes: ['resize image', 'image dimensions', 'compress image', 'convert image format'],
|
|
106
|
+
},
|
|
107
|
+
// Memory - exclude system memory tools
|
|
108
|
+
{
|
|
109
|
+
capability: 'memory',
|
|
110
|
+
namePatterns: /\bmemory_add\b|\bmemory_search\b|\bmemory_list\b|\bmemory_delete\b|\bsave_memory\b|\bget_memory\b|\bcontext_store\b/,
|
|
111
|
+
descIncludes: ['context store', 'conversation memory', 'persist memory', 'retrieve memory', 'memory entries'],
|
|
112
|
+
excludeDescIncludes: ['memory usage', 'memory leak', 'low memory', 'memory limit', 'in-memory'],
|
|
113
|
+
},
|
|
114
|
+
// Agent delegation
|
|
115
|
+
{
|
|
116
|
+
capability: 'agent-delegation',
|
|
117
|
+
namePatterns: /\brun_agent\b|\bspawn_agent\b|\bcreate_agent\b|\bagent_task\b/,
|
|
118
|
+
descIncludes: ['delegate to agent', 'spawn agent', 'run agent', 'execute agent', 'multi-agent'],
|
|
119
|
+
},
|
|
120
|
+
// Git operations
|
|
121
|
+
{
|
|
122
|
+
capability: 'git-operations',
|
|
123
|
+
namePatterns: /\bgit\b|\bgit_|github|gitlab|gitea/,
|
|
124
|
+
descPatterns: /\bgit\b|\bgit_|github|gitlab|gitea/,
|
|
125
|
+
descIncludes: ['git repository', 'version control'],
|
|
126
|
+
},
|
|
127
|
+
// Database
|
|
128
|
+
{
|
|
129
|
+
capability: 'database',
|
|
130
|
+
namePatterns: /\bpostgres\b|\bpostgres_|\bsqlite\b|\bsqlite_|\bmysql\b|\bmysql_|\bmongodb\b|\bmongodb_|\bsupabase\b|\bsupabase_|\bfirebase\b|\bfirebase_|\bdynamodb\b|\bdynamodb_|\bredis\b|\bredis_|\bcassandra\b|\bcassandra_|\bsql_query\b|\bdb_query\b|\bexecute_sql\b|\brun_sql\b|\bdb_execute\b|\bdb_insert\b|\bdb_select\b|\bdb_update\b|\bdb_delete\b/,
|
|
131
|
+
descIncludes: ['execute sql', 'database query', 'run sql', 'database operations', 'sql statement'],
|
|
132
|
+
},
|
|
133
|
+
// Deployment
|
|
134
|
+
{
|
|
135
|
+
capability: 'deployment',
|
|
136
|
+
namePatterns: /\bvercel\b|\bvercel_|\bnetlify\b|\bnetlify_|\bheroku\b|\bheroku_|\baws_deploy\b|\bcloud_run\b|\bflyio\b|\brailway\b|\bdeploy_app\b|\bdeploy_site\b|\bdeploy_function\b|\bcreate_deployment\b|\btrigger_deploy\b/,
|
|
137
|
+
descIncludes: ['deploy to production', 'deploy application', 'deployment platform', 'deploy website'],
|
|
138
|
+
},
|
|
139
|
+
// File operations
|
|
140
|
+
{
|
|
141
|
+
capability: 'file-operations',
|
|
142
|
+
namePatterns: /\bfile\b|\bread_file\b|\bwrite_file\b|\bedit_file\b|\bview_file\b|\bcreate_file\b|\bdelete_file\b|\bstr_replace\b|\btext_editor\b/,
|
|
143
|
+
descIncludes: ['read file', 'write file', 'edit file', 'file system', 'file operations'],
|
|
144
|
+
},
|
|
145
|
+
// Testing
|
|
146
|
+
{
|
|
147
|
+
capability: 'testing',
|
|
148
|
+
namePatterns: /\btest\b|_test\b|\btest_|\btesting\b|puppeteer|playwright|cypress|selenium|\bjest\b|_jest_|_jest$|^jest_|vitest|mocha/,
|
|
149
|
+
descIncludes: ['run test', 'execute test', 'browser automation', 'e2e test', 'unit test', 'integration test'],
|
|
150
|
+
},
|
|
151
|
+
// Monitoring
|
|
152
|
+
{
|
|
153
|
+
capability: 'monitoring',
|
|
154
|
+
namePatterns: /sentry|datadog|newrelic|pagerduty|grafana|prometheus|error_track|log_event|alert_/,
|
|
155
|
+
descIncludes: ['error tracking', 'error monitoring', 'application monitoring', 'observability', 'apm', 'alert management'],
|
|
156
|
+
},
|
|
157
|
+
];
|
|
158
|
+
/**
|
|
159
|
+
* Check if a capability rule matches the tool name and description.
|
|
160
|
+
* Checks exclusions first, then inclusions with short-circuit evaluation.
|
|
161
|
+
*/
|
|
162
|
+
function matchesCapabilityRule(rule, toolName, toolDescription) {
|
|
163
|
+
// Check exclusions first (short-circuit on any match)
|
|
164
|
+
if (rule.excludeNamePattern?.test(toolName) ||
|
|
165
|
+
(rule.excludeDescIncludes && containsAny(toolDescription, rule.excludeDescIncludes))) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
// Check inclusions (short-circuit on first match)
|
|
169
|
+
return !!(rule.namePatterns?.test(toolName) ||
|
|
170
|
+
rule.descPatterns?.test(toolDescription) ||
|
|
171
|
+
(rule.nameIncludes && containsAny(toolName, rule.nameIncludes)) ||
|
|
172
|
+
(rule.descIncludes && containsAny(toolDescription, rule.descIncludes)));
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Infer capability from tool name and description.
|
|
176
|
+
* Uses heuristics to determine what a tool does.
|
|
177
|
+
*
|
|
178
|
+
* @param tool - The LLM tool to analyze
|
|
179
|
+
* @returns Array of inferred capabilities
|
|
180
|
+
*/
|
|
181
|
+
export function inferToolCapability(tool) {
|
|
182
|
+
const toolName = tool.function.name.toLowerCase();
|
|
183
|
+
const toolDescription = (tool.function.description || '').toLowerCase();
|
|
184
|
+
const capabilities = [];
|
|
185
|
+
// Apply standard rules
|
|
186
|
+
for (const rule of CAPABILITY_RULES) {
|
|
187
|
+
if (matchesCapabilityRule(rule, toolName, toolDescription)) {
|
|
188
|
+
capabilities.push(rule.capability);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Design detection: Figma-specific vs general design tools
|
|
192
|
+
const hasFigma = toolName.includes('figma') || toolDescription.includes('figma');
|
|
193
|
+
if (hasFigma) {
|
|
194
|
+
capabilities.push('design-figma');
|
|
195
|
+
}
|
|
196
|
+
else if (/\bdesign_system\b|\bdesign_token\b|\bui_design\b|\bget_design\b|\bcreate_design\b/.test(toolName) ||
|
|
197
|
+
containsAny(toolDescription, ['design system', 'design tokens'])) {
|
|
198
|
+
capabilities.push('design-general');
|
|
199
|
+
}
|
|
200
|
+
return capabilities;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Registry for managing tool priorities and selection
|
|
204
|
+
*/
|
|
205
|
+
export class PriorityRegistry {
|
|
206
|
+
provider;
|
|
207
|
+
toolMetadata = new Map();
|
|
208
|
+
constructor(provider) {
|
|
209
|
+
this.provider = provider || getActiveProvider();
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Analyze a tool and determine its metadata
|
|
213
|
+
*/
|
|
214
|
+
analyzeToolMetadata(tool) {
|
|
215
|
+
const toolName = tool.function.name;
|
|
216
|
+
// Check cache first (most common path)
|
|
217
|
+
const cached = this.toolMetadata.get(toolName);
|
|
218
|
+
if (cached) {
|
|
219
|
+
return cached;
|
|
220
|
+
}
|
|
221
|
+
const serverName = extractServerNameFromTool(toolName);
|
|
222
|
+
const mapping = serverName ? getServerCapabilityMapping(serverName) : undefined;
|
|
223
|
+
// Determine priority: known MCP > unknown MCP > built-in
|
|
224
|
+
const priority = mapping
|
|
225
|
+
? getServerPriority(serverName, this.provider.name)
|
|
226
|
+
: toolName.startsWith(MCP_TOOL_PREFIX)
|
|
227
|
+
? ToolPriority.COMMUNITY_MCP
|
|
228
|
+
: ToolPriority.BUILTIN_TOOL;
|
|
229
|
+
// Merge registered capabilities with inferred ones
|
|
230
|
+
const baseCapabilities = mapping?.capabilities ?? [];
|
|
231
|
+
const inferredCapabilities = inferToolCapability(tool);
|
|
232
|
+
const capabilities = baseCapabilities.length > 0
|
|
233
|
+
? [...baseCapabilities, ...inferredCapabilities.filter(c => !baseCapabilities.includes(c))]
|
|
234
|
+
: inferredCapabilities;
|
|
235
|
+
const metadata = { name: toolName, capabilities, priority, serverName };
|
|
236
|
+
this.toolMetadata.set(toolName, metadata);
|
|
237
|
+
return metadata;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Check if a tool should be hidden based on capability conflicts
|
|
241
|
+
* Returns reason if hidden, undefined if should be shown
|
|
242
|
+
*
|
|
243
|
+
* IMPORTANT: A tool is only hidden if ALL of its capabilities are superseded
|
|
244
|
+
* by higher-priority alternatives. If a tool provides unique capabilities
|
|
245
|
+
* (e.g., AutomatosX's memory/agent-delegation), it should NOT be hidden
|
|
246
|
+
* even if some of its capabilities (e.g., web-search) are better served elsewhere.
|
|
247
|
+
*/
|
|
248
|
+
shouldHideTool(tool, allTools) {
|
|
249
|
+
const metadata = this.analyzeToolMetadata(tool);
|
|
250
|
+
const { capabilities, name: toolName, priority: toolPriority } = metadata;
|
|
251
|
+
// If tool has no capabilities detected, don't hide it
|
|
252
|
+
if (capabilities.length === 0) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
// Track superseded capabilities - only collect details if all are superseded
|
|
256
|
+
const supersededCapabilities = [];
|
|
257
|
+
for (const capability of capabilities) {
|
|
258
|
+
// Find the highest priority tool for this capability
|
|
259
|
+
// This includes native API capabilities (priority 100) as virtual tools
|
|
260
|
+
const highestPriorityTool = this.findHighestPriorityTool(allTools, capability);
|
|
261
|
+
// Check if this capability is NOT superseded (early exit optimization)
|
|
262
|
+
const isSuperseded = highestPriorityTool &&
|
|
263
|
+
highestPriorityTool.name !== toolName &&
|
|
264
|
+
(highestPriorityTool.priority - toolPriority) >= SUPERSEDE_THRESHOLD;
|
|
265
|
+
if (!isSuperseded) {
|
|
266
|
+
// Found a unique capability - tool should not be hidden
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
supersededCapabilities.push(`${capability} (by ${highestPriorityTool.name})`);
|
|
270
|
+
}
|
|
271
|
+
// All capabilities are superseded - hide this tool
|
|
272
|
+
return `All capabilities superseded: ${supersededCapabilities.join(', ')}`;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Find the highest priority tool for a given capability
|
|
276
|
+
* Also considers native API capabilities which have priority NATIVE_API (100)
|
|
277
|
+
*/
|
|
278
|
+
findHighestPriorityTool(tools, capability) {
|
|
279
|
+
// Native capabilities have highest priority (100) - early return optimization
|
|
280
|
+
if (hasNativeCapability(this.provider.name, capability)) {
|
|
281
|
+
return {
|
|
282
|
+
name: `${NATIVE_CAPABILITY_PREFIX}${capability}`,
|
|
283
|
+
capabilities: [capability],
|
|
284
|
+
priority: ToolPriority.NATIVE_API,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
// Find highest priority tool for this capability
|
|
288
|
+
let highest;
|
|
289
|
+
for (const tool of tools) {
|
|
290
|
+
const metadata = this.analyzeToolMetadata(tool);
|
|
291
|
+
if (metadata.capabilities.includes(capability) && (!highest || metadata.priority > highest.priority)) {
|
|
292
|
+
highest = metadata;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return highest;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Filter tools based on priority, removing lower-priority duplicates
|
|
299
|
+
* Returns filtered tools and a list of hidden tools (for debugging)
|
|
300
|
+
*/
|
|
301
|
+
filterTools(tools) {
|
|
302
|
+
const filtered = [];
|
|
303
|
+
const hidden = [];
|
|
304
|
+
// Single pass: analyze and filter in one loop
|
|
305
|
+
for (const tool of tools) {
|
|
306
|
+
// analyzeToolMetadata caches results, so shouldHideTool benefits from this
|
|
307
|
+
const hideReason = this.shouldHideTool(tool, tools);
|
|
308
|
+
if (hideReason) {
|
|
309
|
+
hidden.push({ tool, reason: hideReason });
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
filtered.push(tool);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return { filtered, hidden };
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get capability-based guidance for the system prompt
|
|
319
|
+
* Helps the LLM understand which tools to prefer
|
|
320
|
+
* Uses flexible provider matching to handle variants like 'grok-beta', 'glm-4'
|
|
321
|
+
*
|
|
322
|
+
* @param connectedServers - Optional list of currently connected MCP server names.
|
|
323
|
+
* If provided, guidance is only given for connected servers.
|
|
324
|
+
*/
|
|
325
|
+
getCapabilityGuidance(connectedServers) {
|
|
326
|
+
const guidance = [];
|
|
327
|
+
const providerName = this.provider.name;
|
|
328
|
+
// Check if a server is connected (or if we don't have connection info)
|
|
329
|
+
const isConnected = (target) => !connectedServers || connectedServers.some(s => serverNameMatches(s, target));
|
|
330
|
+
// Add provider-specific guidance
|
|
331
|
+
if (providerMatches(providerName, 'grok') || providerMatches(providerName, 'gemini')) {
|
|
332
|
+
guidance.push('For web searches, use NATIVE search capabilities (simply ask questions that require current information).', 'Do NOT use MCP web search tools when native search is available.');
|
|
333
|
+
}
|
|
334
|
+
else if (providerMatches(providerName, 'glm') && isConnected(KNOWN_SERVERS.ZAI_WEB_SEARCH)) {
|
|
335
|
+
guidance.push(`For web searches, use Z.AI MCP tools (${KNOWN_SERVERS.ZAI_WEB_SEARCH}) for best results.`, 'Z.AI tools are optimized for GLM integration.');
|
|
336
|
+
}
|
|
337
|
+
// Add MCP guidance only for servers that are actually connected
|
|
338
|
+
if (isConnected(KNOWN_SERVERS.AUTOMATOSX)) {
|
|
339
|
+
guidance.push('For memory and context management, use AutomatosX MCP tools.');
|
|
340
|
+
}
|
|
341
|
+
if (isConnected(KNOWN_SERVERS.FIGMA)) {
|
|
342
|
+
guidance.push('For design tasks involving Figma, use Figma MCP tools.');
|
|
343
|
+
}
|
|
344
|
+
if (isConnected(KNOWN_SERVERS.GITHUB)) {
|
|
345
|
+
guidance.push('For GitHub operations, use GitHub MCP tools.');
|
|
346
|
+
}
|
|
347
|
+
return guidance;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get tools sorted by priority for a given capability
|
|
351
|
+
*/
|
|
352
|
+
getToolsForCapability(tools, capability) {
|
|
353
|
+
// Collect matching tools with their priorities in single pass
|
|
354
|
+
const matching = [];
|
|
355
|
+
for (const tool of tools) {
|
|
356
|
+
const metadata = this.analyzeToolMetadata(tool);
|
|
357
|
+
if (metadata.capabilities.includes(capability)) {
|
|
358
|
+
matching.push({ tool, priority: metadata.priority });
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
// Sort and extract tools
|
|
362
|
+
return matching
|
|
363
|
+
.sort((a, b) => b.priority - a.priority)
|
|
364
|
+
.map(({ tool }) => tool);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Clear the metadata cache (useful for testing or provider changes)
|
|
368
|
+
*/
|
|
369
|
+
clearCache() {
|
|
370
|
+
this.toolMetadata.clear();
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Set provider (useful when provider changes mid-session)
|
|
374
|
+
*/
|
|
375
|
+
setProvider(provider) {
|
|
376
|
+
this.provider = provider;
|
|
377
|
+
this.clearCache();
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
// Singleton instance
|
|
381
|
+
let registryInstance = null;
|
|
382
|
+
/**
|
|
383
|
+
* Get the priority registry singleton
|
|
384
|
+
*/
|
|
385
|
+
export function getPriorityRegistry() {
|
|
386
|
+
return registryInstance ??= new PriorityRegistry();
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Reset the priority registry (for testing or provider changes)
|
|
390
|
+
*/
|
|
391
|
+
export function resetPriorityRegistry() {
|
|
392
|
+
registryInstance?.clearCache();
|
|
393
|
+
registryInstance = null;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Update the registry when provider changes
|
|
397
|
+
*/
|
|
398
|
+
export function updatePriorityRegistryProvider(provider) {
|
|
399
|
+
getPriorityRegistry().setProvider(provider);
|
|
400
|
+
}
|
|
401
|
+
//# sourceMappingURL=priority-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priority-registry.js","sourceRoot":"","sources":["../../src/tools/priority-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,iBAAiB,EAA2B,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAEL,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,mBAAmB,EACnB,0BAA0B,EAC1B,iBAAiB,EACjB,eAAe,GAChB,MAAM,eAAe,CAAC;AAEvB;;;GAGG;AACH,MAAM,eAAe,GAAG,OAAO,CAAC;AAEhC;;GAEG;AACH,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC;;;GAGG;AACH,MAAM,aAAa,GAAG;IACpB,cAAc,EAAE,gBAAgB;IAChC,UAAU,EAAE,YAAY;IACxB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;CACR,CAAC;AAoBX;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,yBAAyB,CAAC,QAAgB;IACxD,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QAC1C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,gEAAgE;IAChE,qFAAqF;IACrF,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACjD,sGAAsG;IACtG,0FAA0F;IAC1F,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAClC,+CAA+C;QAC/C,IAAI,OA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AAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;YACvD,CAAC;QACH,CAAC;QAED,yBAAyB;QACzB,OAAO,QAAQ;aACZ,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;aACvC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,QAA4B;QACtC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;CACF;AAED,qBAAqB;AACrB,IAAI,gBAAgB,GAA4B,IAAI,CAAC;AAErD;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,gBAAgB,KAAK,IAAI,gBAAgB,EAAE,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACnC,gBAAgB,EAAE,UAAU,EAAE,CAAC;IAC/B,gBAAgB,GAAG,IAAI,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAAC,QAA4B;IACzE,mBAAmB,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Priority System
|
|
3
|
+
*
|
|
4
|
+
* Defines priority levels and capability types for intelligent tool selection.
|
|
5
|
+
* When multiple tools can handle the same task, the system prefers higher-priority tools.
|
|
6
|
+
*
|
|
7
|
+
* Priority Order:
|
|
8
|
+
* 1. Native API capabilities (e.g., Grok's built-in search)
|
|
9
|
+
* 2. Provider-specific MCP (e.g., Z.AI MCP for GLM)
|
|
10
|
+
* 3. Domain-specific MCP (e.g., Figma MCP for design)
|
|
11
|
+
* 4. Official MCP servers
|
|
12
|
+
* 5. Community MCP servers
|
|
13
|
+
* 6. General-purpose MCP (e.g., AutomatosX)
|
|
14
|
+
* 7. Built-in tools (fallback)
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Capability types that tools can provide
|
|
18
|
+
*/
|
|
19
|
+
export type ToolCapability = 'web-search' | 'web-fetch' | 'vision' | 'code-generation' | 'file-operations' | 'git-operations' | 'design-figma' | 'design-general' | 'database' | 'deployment' | 'memory' | 'agent-delegation' | 'testing' | 'monitoring';
|
|
20
|
+
/**
|
|
21
|
+
* Priority levels for tool selection
|
|
22
|
+
* Higher values = higher priority = preferred tool
|
|
23
|
+
*/
|
|
24
|
+
export declare enum ToolPriority {
|
|
25
|
+
/** Built into provider API (highest priority) */
|
|
26
|
+
NATIVE_API = 100,
|
|
27
|
+
/** Provider-specific MCP (e.g., Z.AI for GLM) */
|
|
28
|
+
PROVIDER_MCP = 80,
|
|
29
|
+
/** Domain-specific MCP (e.g., Figma for design) */
|
|
30
|
+
DOMAIN_SPECIFIC = 60,
|
|
31
|
+
/** Official MCP servers (e.g., @modelcontextprotocol/*) */
|
|
32
|
+
OFFICIAL_MCP = 40,
|
|
33
|
+
/** Community MCP servers */
|
|
34
|
+
COMMUNITY_MCP = 20,
|
|
35
|
+
/** General-purpose MCP (e.g., AutomatosX) */
|
|
36
|
+
GENERAL_MCP = 10,
|
|
37
|
+
/** Built-in ax-cli tools (fallback) */
|
|
38
|
+
BUILTIN_TOOL = 5
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Priority boost applied when a server has affinity for the current provider.
|
|
42
|
+
* This ensures provider-affinity servers beat same-level servers without affinity.
|
|
43
|
+
*/
|
|
44
|
+
export declare const PROVIDER_AFFINITY_BOOST = 10;
|
|
45
|
+
/**
|
|
46
|
+
* Minimum priority difference required to consider a capability superseded.
|
|
47
|
+
* Prevents minor priority differences from hiding useful tools.
|
|
48
|
+
*/
|
|
49
|
+
export declare const SUPERSEDE_THRESHOLD = 15;
|
|
50
|
+
/**
|
|
51
|
+
* Delimiters used to separate base names from variant suffixes.
|
|
52
|
+
* e.g., 'grok-beta' uses '-', 'automatosx_glm' uses '_'
|
|
53
|
+
*/
|
|
54
|
+
export declare const VARIANT_DELIMITERS: readonly ["-", "_"];
|
|
55
|
+
/**
|
|
56
|
+
* Prefix used for virtual native capability tool names.
|
|
57
|
+
* e.g., 'native_web-search' represents Grok's native search capability
|
|
58
|
+
*/
|
|
59
|
+
export declare const NATIVE_CAPABILITY_PREFIX = "native_";
|
|
60
|
+
/**
|
|
61
|
+
* Check if a name starts with a base name followed by a variant delimiter.
|
|
62
|
+
* Used to match variant names like 'grok-beta' to base name 'grok'.
|
|
63
|
+
*
|
|
64
|
+
* @param fullName - The full name to check (e.g., 'grok-beta')
|
|
65
|
+
* @param baseName - The base name to match against (e.g., 'grok')
|
|
66
|
+
* @returns True if fullName is a variant of baseName
|
|
67
|
+
*/
|
|
68
|
+
export declare function isVariantOf(fullName: string, baseName: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Provider names for capability mapping
|
|
71
|
+
*/
|
|
72
|
+
export type ProviderName = 'grok' | 'glm' | 'claude' | 'openai' | 'gemini';
|
|
73
|
+
/**
|
|
74
|
+
* Native capabilities built into provider APIs
|
|
75
|
+
* These don't require MCP - they're part of the API itself
|
|
76
|
+
*/
|
|
77
|
+
export declare const PROVIDER_NATIVE_CAPABILITIES: Record<ProviderName, ToolCapability[]>;
|
|
78
|
+
/**
|
|
79
|
+
* MCP server capability mapping
|
|
80
|
+
* Defines which capabilities each MCP server provides and its priority
|
|
81
|
+
*/
|
|
82
|
+
export interface MCPCapabilityMapping {
|
|
83
|
+
/** MCP server name (e.g., 'figma', 'github', 'automatosx') */
|
|
84
|
+
serverName: string;
|
|
85
|
+
/** Capabilities this server provides */
|
|
86
|
+
capabilities: ToolCapability[];
|
|
87
|
+
/** Priority level for this server */
|
|
88
|
+
priority: ToolPriority;
|
|
89
|
+
/** Preferred providers for this server (if any) */
|
|
90
|
+
providerAffinity?: ProviderName[];
|
|
91
|
+
/** Whether this is an official MCP server */
|
|
92
|
+
isOfficial?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Known MCP server capability registry
|
|
96
|
+
* Add new servers here as they become available
|
|
97
|
+
*/
|
|
98
|
+
export declare const MCP_CAPABILITY_REGISTRY: MCPCapabilityMapping[];
|
|
99
|
+
/**
|
|
100
|
+
* Get capability mapping for a server by name.
|
|
101
|
+
* Supports exact matches and variant matches (e.g., 'automatosx-glm' matches 'automatosx').
|
|
102
|
+
* Case-insensitive matching for robustness.
|
|
103
|
+
*
|
|
104
|
+
* @param serverName - The server name to look up (may include variant suffix)
|
|
105
|
+
* @returns The capability mapping, or undefined if not found
|
|
106
|
+
*/
|
|
107
|
+
export declare function getServerCapabilityMapping(serverName: string): MCPCapabilityMapping | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* Check if a provider has native support for a capability.
|
|
110
|
+
* Supports provider variants (e.g., 'grok-beta' matches 'grok' native capabilities)
|
|
111
|
+
*
|
|
112
|
+
* @param providerName - The provider name (may include variant suffix)
|
|
113
|
+
* @param capability - The capability to check
|
|
114
|
+
* @returns True if the provider natively supports the capability
|
|
115
|
+
*/
|
|
116
|
+
export declare function hasNativeCapability(providerName: string, capability: ToolCapability): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Check if a provider matches a base provider name.
|
|
119
|
+
* e.g., 'grok-beta' matches 'grok', 'glm-4' matches 'glm'
|
|
120
|
+
*
|
|
121
|
+
* @param providerName - The provider name to check (may include variant suffix)
|
|
122
|
+
* @param baseProvider - The base provider to match against
|
|
123
|
+
* @returns True if the provider matches the base provider
|
|
124
|
+
*/
|
|
125
|
+
export declare function providerMatches(providerName: string, baseProvider: ProviderName): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Get the priority for a server, considering provider affinity.
|
|
128
|
+
*
|
|
129
|
+
* @param serverName - The MCP server name
|
|
130
|
+
* @param providerName - Optional provider name for affinity boosting
|
|
131
|
+
* @returns The priority value (higher = more preferred)
|
|
132
|
+
*/
|
|
133
|
+
export declare function getServerPriority(serverName: string, providerName?: string): number;
|
|
134
|
+
/**
|
|
135
|
+
* Check if a server should be preferred for a given capability and provider.
|
|
136
|
+
*
|
|
137
|
+
* A server is preferred if:
|
|
138
|
+
* 1. The provider does NOT have native support for this capability, AND
|
|
139
|
+
* 2. Either:
|
|
140
|
+
* a. It has provider affinity for the current provider, OR
|
|
141
|
+
* b. It has the highest priority among all servers providing this capability
|
|
142
|
+
*
|
|
143
|
+
* Note: If the provider has native capability support, NO MCP server should be preferred.
|
|
144
|
+
*
|
|
145
|
+
* @param serverName - The MCP server name
|
|
146
|
+
* @param capability - The capability to check
|
|
147
|
+
* @param providerName - The current provider name
|
|
148
|
+
* @returns True if the server should be preferred for this capability
|
|
149
|
+
*/
|
|
150
|
+
export declare function shouldPreferServer(serverName: string, capability: ToolCapability, providerName: string): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Get all servers that provide a given capability, sorted by priority.
|
|
153
|
+
*
|
|
154
|
+
* @param capability - The capability to search for
|
|
155
|
+
* @param providerName - Optional provider name for affinity-based priority boosting
|
|
156
|
+
* @returns Array of server mappings sorted by priority (highest first)
|
|
157
|
+
*/
|
|
158
|
+
export declare function getServersForCapability(capability: ToolCapability, providerName?: string): MCPCapabilityMapping[];
|