claude-flow 1.0.0
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/LICENSE +21 -0
- package/README.md +612 -0
- package/bin/claude-flow +0 -0
- package/bin/claude-flow-simple +0 -0
- package/bin/claude-flow-typecheck +0 -0
- package/deno.json +84 -0
- package/package.json +45 -0
- package/scripts/check-links.ts +274 -0
- package/scripts/check-performance-regression.ts +168 -0
- package/scripts/claude-sparc.sh +562 -0
- package/scripts/coverage-report.ts +692 -0
- package/scripts/demo-task-system.ts +224 -0
- package/scripts/install.js +72 -0
- package/scripts/test-batch-tasks.ts +29 -0
- package/scripts/test-coordination-features.ts +238 -0
- package/scripts/test-mcp.ts +251 -0
- package/scripts/test-runner.ts +571 -0
- package/scripts/validate-examples.ts +288 -0
- package/src/cli/cli-core.ts +273 -0
- package/src/cli/commands/agent.ts +83 -0
- package/src/cli/commands/config.ts +442 -0
- package/src/cli/commands/help.ts +765 -0
- package/src/cli/commands/index.ts +963 -0
- package/src/cli/commands/mcp.ts +191 -0
- package/src/cli/commands/memory.ts +74 -0
- package/src/cli/commands/monitor.ts +403 -0
- package/src/cli/commands/session.ts +595 -0
- package/src/cli/commands/start.ts +156 -0
- package/src/cli/commands/status.ts +345 -0
- package/src/cli/commands/task.ts +79 -0
- package/src/cli/commands/workflow.ts +763 -0
- package/src/cli/completion.ts +553 -0
- package/src/cli/formatter.ts +310 -0
- package/src/cli/index.ts +211 -0
- package/src/cli/main.ts +23 -0
- package/src/cli/repl.ts +1050 -0
- package/src/cli/simple-cli.js +211 -0
- package/src/cli/simple-cli.ts +211 -0
- package/src/coordination/README.md +400 -0
- package/src/coordination/advanced-scheduler.ts +487 -0
- package/src/coordination/circuit-breaker.ts +366 -0
- package/src/coordination/conflict-resolution.ts +490 -0
- package/src/coordination/dependency-graph.ts +475 -0
- package/src/coordination/index.ts +63 -0
- package/src/coordination/manager.ts +460 -0
- package/src/coordination/messaging.ts +290 -0
- package/src/coordination/metrics.ts +585 -0
- package/src/coordination/resources.ts +322 -0
- package/src/coordination/scheduler.ts +390 -0
- package/src/coordination/work-stealing.ts +224 -0
- package/src/core/config.ts +627 -0
- package/src/core/event-bus.ts +186 -0
- package/src/core/json-persistence.ts +183 -0
- package/src/core/logger.ts +262 -0
- package/src/core/orchestrator-fixed.ts +312 -0
- package/src/core/orchestrator.ts +1234 -0
- package/src/core/persistence.ts +276 -0
- package/src/mcp/auth.ts +438 -0
- package/src/mcp/claude-flow-tools.ts +1280 -0
- package/src/mcp/load-balancer.ts +510 -0
- package/src/mcp/router.ts +240 -0
- package/src/mcp/server.ts +548 -0
- package/src/mcp/session-manager.ts +418 -0
- package/src/mcp/tools.ts +180 -0
- package/src/mcp/transports/base.ts +21 -0
- package/src/mcp/transports/http.ts +457 -0
- package/src/mcp/transports/stdio.ts +254 -0
- package/src/memory/backends/base.ts +22 -0
- package/src/memory/backends/markdown.ts +283 -0
- package/src/memory/backends/sqlite.ts +329 -0
- package/src/memory/cache.ts +238 -0
- package/src/memory/indexer.ts +238 -0
- package/src/memory/manager.ts +572 -0
- package/src/terminal/adapters/base.ts +29 -0
- package/src/terminal/adapters/native.ts +504 -0
- package/src/terminal/adapters/vscode.ts +340 -0
- package/src/terminal/manager.ts +308 -0
- package/src/terminal/pool.ts +271 -0
- package/src/terminal/session.ts +250 -0
- package/src/terminal/vscode-bridge.ts +242 -0
- package/src/utils/errors.ts +231 -0
- package/src/utils/helpers.ts +476 -0
- package/src/utils/types.ts +493 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request router for MCP
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { MCPRequest } from '../utils/types.ts';
|
|
6
|
+
import { ILogger } from '../core/logger.ts';
|
|
7
|
+
import { MCPMethodNotFoundError } from '../utils/errors.ts';
|
|
8
|
+
import { ToolRegistry } from './tools.ts';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Request router implementation
|
|
12
|
+
*/
|
|
13
|
+
export class RequestRouter {
|
|
14
|
+
private totalRequests = 0;
|
|
15
|
+
private successfulRequests = 0;
|
|
16
|
+
private failedRequests = 0;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
private toolRegistry: ToolRegistry,
|
|
20
|
+
private logger: ILogger,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Routes a request to the appropriate handler
|
|
25
|
+
*/
|
|
26
|
+
async route(request: MCPRequest): Promise<unknown> {
|
|
27
|
+
this.totalRequests++;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
// Parse method to determine handler
|
|
31
|
+
const { method, params } = request;
|
|
32
|
+
|
|
33
|
+
// Handle built-in methods
|
|
34
|
+
if (method.startsWith('rpc.')) {
|
|
35
|
+
return await this.handleRPCMethod(method, params);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Handle tool invocations
|
|
39
|
+
if (method.startsWith('tools.')) {
|
|
40
|
+
return await this.handleToolMethod(method, params);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Try to execute as a tool directly
|
|
44
|
+
const tool = this.toolRegistry.getTool(method);
|
|
45
|
+
if (tool) {
|
|
46
|
+
const result = await this.toolRegistry.executeTool(method, params);
|
|
47
|
+
this.successfulRequests++;
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Method not found
|
|
52
|
+
throw new MCPMethodNotFoundError(method);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
this.failedRequests++;
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Gets router metrics
|
|
61
|
+
*/
|
|
62
|
+
getMetrics(): {
|
|
63
|
+
totalRequests: number;
|
|
64
|
+
successfulRequests: number;
|
|
65
|
+
failedRequests: number;
|
|
66
|
+
} {
|
|
67
|
+
return {
|
|
68
|
+
totalRequests: this.totalRequests,
|
|
69
|
+
successfulRequests: this.successfulRequests,
|
|
70
|
+
failedRequests: this.failedRequests,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Handles built-in RPC methods
|
|
76
|
+
*/
|
|
77
|
+
private async handleRPCMethod(method: string, params: unknown): Promise<unknown> {
|
|
78
|
+
switch (method) {
|
|
79
|
+
case 'rpc.discover':
|
|
80
|
+
return this.discoverMethods();
|
|
81
|
+
|
|
82
|
+
case 'rpc.ping':
|
|
83
|
+
return { pong: true };
|
|
84
|
+
|
|
85
|
+
case 'rpc.describe':
|
|
86
|
+
return this.describeMethod(params);
|
|
87
|
+
|
|
88
|
+
default:
|
|
89
|
+
throw new MCPMethodNotFoundError(method);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Handles tool-related methods
|
|
95
|
+
*/
|
|
96
|
+
private async handleToolMethod(method: string, params: unknown): Promise<unknown> {
|
|
97
|
+
switch (method) {
|
|
98
|
+
case 'tools.list':
|
|
99
|
+
return this.toolRegistry.listTools();
|
|
100
|
+
|
|
101
|
+
case 'tools.invoke':
|
|
102
|
+
return await this.invokeTool(params);
|
|
103
|
+
|
|
104
|
+
case 'tools.describe':
|
|
105
|
+
return this.describeTool(params);
|
|
106
|
+
|
|
107
|
+
default:
|
|
108
|
+
throw new MCPMethodNotFoundError(method);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Discovers all available methods
|
|
114
|
+
*/
|
|
115
|
+
private discoverMethods(): Record<string, string> {
|
|
116
|
+
const methods: Record<string, string> = {
|
|
117
|
+
'rpc.discover': 'Discover all available methods',
|
|
118
|
+
'rpc.ping': 'Ping the server',
|
|
119
|
+
'rpc.describe': 'Describe a specific method',
|
|
120
|
+
'tools.list': 'List all available tools',
|
|
121
|
+
'tools.invoke': 'Invoke a specific tool',
|
|
122
|
+
'tools.describe': 'Describe a specific tool',
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Add all registered tools
|
|
126
|
+
for (const tool of this.toolRegistry.listTools()) {
|
|
127
|
+
methods[tool.name] = tool.description;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return methods;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Describes a specific method
|
|
135
|
+
*/
|
|
136
|
+
private describeMethod(params: unknown): unknown {
|
|
137
|
+
if (!params || typeof params !== 'object' || !('method' in params)) {
|
|
138
|
+
throw new Error('Invalid params: method required');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const { method } = params as { method: string };
|
|
142
|
+
|
|
143
|
+
// Check if it's a tool
|
|
144
|
+
const tool = this.toolRegistry.getTool(method);
|
|
145
|
+
if (tool) {
|
|
146
|
+
return {
|
|
147
|
+
name: tool.name,
|
|
148
|
+
description: tool.description,
|
|
149
|
+
inputSchema: tool.inputSchema,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Check built-in methods
|
|
154
|
+
const builtInMethods: Record<string, unknown> = {
|
|
155
|
+
'rpc.discover': {
|
|
156
|
+
description: 'Discover all available methods',
|
|
157
|
+
inputSchema: { type: 'object', properties: {} },
|
|
158
|
+
},
|
|
159
|
+
'rpc.ping': {
|
|
160
|
+
description: 'Ping the server',
|
|
161
|
+
inputSchema: { type: 'object', properties: {} },
|
|
162
|
+
},
|
|
163
|
+
'rpc.describe': {
|
|
164
|
+
description: 'Describe a specific method',
|
|
165
|
+
inputSchema: {
|
|
166
|
+
type: 'object',
|
|
167
|
+
properties: {
|
|
168
|
+
method: { type: 'string' },
|
|
169
|
+
},
|
|
170
|
+
required: ['method'],
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
'tools.list': {
|
|
174
|
+
description: 'List all available tools',
|
|
175
|
+
inputSchema: { type: 'object', properties: {} },
|
|
176
|
+
},
|
|
177
|
+
'tools.invoke': {
|
|
178
|
+
description: 'Invoke a specific tool',
|
|
179
|
+
inputSchema: {
|
|
180
|
+
type: 'object',
|
|
181
|
+
properties: {
|
|
182
|
+
tool: { type: 'string' },
|
|
183
|
+
input: { type: 'object' },
|
|
184
|
+
},
|
|
185
|
+
required: ['tool', 'input'],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
'tools.describe': {
|
|
189
|
+
description: 'Describe a specific tool',
|
|
190
|
+
inputSchema: {
|
|
191
|
+
type: 'object',
|
|
192
|
+
properties: {
|
|
193
|
+
tool: { type: 'string' },
|
|
194
|
+
},
|
|
195
|
+
required: ['tool'],
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
if (method in builtInMethods) {
|
|
201
|
+
return builtInMethods[method];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
throw new MCPMethodNotFoundError(method);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Invokes a tool
|
|
209
|
+
*/
|
|
210
|
+
private async invokeTool(params: unknown): Promise<unknown> {
|
|
211
|
+
if (!params || typeof params !== 'object' || !('tool' in params)) {
|
|
212
|
+
throw new Error('Invalid params: tool required');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const { tool, input } = params as { tool: string; input?: unknown };
|
|
216
|
+
return await this.toolRegistry.executeTool(tool, input || {});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Describes a specific tool
|
|
221
|
+
*/
|
|
222
|
+
private describeTool(params: unknown): unknown {
|
|
223
|
+
if (!params || typeof params !== 'object' || !('tool' in params)) {
|
|
224
|
+
throw new Error('Invalid params: tool required');
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const { tool: toolName } = params as { tool: string };
|
|
228
|
+
const tool = this.toolRegistry.getTool(toolName);
|
|
229
|
+
|
|
230
|
+
if (!tool) {
|
|
231
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
name: tool.name,
|
|
236
|
+
description: tool.description,
|
|
237
|
+
inputSchema: tool.inputSchema,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|