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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +612 -0
  3. package/bin/claude-flow +0 -0
  4. package/bin/claude-flow-simple +0 -0
  5. package/bin/claude-flow-typecheck +0 -0
  6. package/deno.json +84 -0
  7. package/package.json +45 -0
  8. package/scripts/check-links.ts +274 -0
  9. package/scripts/check-performance-regression.ts +168 -0
  10. package/scripts/claude-sparc.sh +562 -0
  11. package/scripts/coverage-report.ts +692 -0
  12. package/scripts/demo-task-system.ts +224 -0
  13. package/scripts/install.js +72 -0
  14. package/scripts/test-batch-tasks.ts +29 -0
  15. package/scripts/test-coordination-features.ts +238 -0
  16. package/scripts/test-mcp.ts +251 -0
  17. package/scripts/test-runner.ts +571 -0
  18. package/scripts/validate-examples.ts +288 -0
  19. package/src/cli/cli-core.ts +273 -0
  20. package/src/cli/commands/agent.ts +83 -0
  21. package/src/cli/commands/config.ts +442 -0
  22. package/src/cli/commands/help.ts +765 -0
  23. package/src/cli/commands/index.ts +963 -0
  24. package/src/cli/commands/mcp.ts +191 -0
  25. package/src/cli/commands/memory.ts +74 -0
  26. package/src/cli/commands/monitor.ts +403 -0
  27. package/src/cli/commands/session.ts +595 -0
  28. package/src/cli/commands/start.ts +156 -0
  29. package/src/cli/commands/status.ts +345 -0
  30. package/src/cli/commands/task.ts +79 -0
  31. package/src/cli/commands/workflow.ts +763 -0
  32. package/src/cli/completion.ts +553 -0
  33. package/src/cli/formatter.ts +310 -0
  34. package/src/cli/index.ts +211 -0
  35. package/src/cli/main.ts +23 -0
  36. package/src/cli/repl.ts +1050 -0
  37. package/src/cli/simple-cli.js +211 -0
  38. package/src/cli/simple-cli.ts +211 -0
  39. package/src/coordination/README.md +400 -0
  40. package/src/coordination/advanced-scheduler.ts +487 -0
  41. package/src/coordination/circuit-breaker.ts +366 -0
  42. package/src/coordination/conflict-resolution.ts +490 -0
  43. package/src/coordination/dependency-graph.ts +475 -0
  44. package/src/coordination/index.ts +63 -0
  45. package/src/coordination/manager.ts +460 -0
  46. package/src/coordination/messaging.ts +290 -0
  47. package/src/coordination/metrics.ts +585 -0
  48. package/src/coordination/resources.ts +322 -0
  49. package/src/coordination/scheduler.ts +390 -0
  50. package/src/coordination/work-stealing.ts +224 -0
  51. package/src/core/config.ts +627 -0
  52. package/src/core/event-bus.ts +186 -0
  53. package/src/core/json-persistence.ts +183 -0
  54. package/src/core/logger.ts +262 -0
  55. package/src/core/orchestrator-fixed.ts +312 -0
  56. package/src/core/orchestrator.ts +1234 -0
  57. package/src/core/persistence.ts +276 -0
  58. package/src/mcp/auth.ts +438 -0
  59. package/src/mcp/claude-flow-tools.ts +1280 -0
  60. package/src/mcp/load-balancer.ts +510 -0
  61. package/src/mcp/router.ts +240 -0
  62. package/src/mcp/server.ts +548 -0
  63. package/src/mcp/session-manager.ts +418 -0
  64. package/src/mcp/tools.ts +180 -0
  65. package/src/mcp/transports/base.ts +21 -0
  66. package/src/mcp/transports/http.ts +457 -0
  67. package/src/mcp/transports/stdio.ts +254 -0
  68. package/src/memory/backends/base.ts +22 -0
  69. package/src/memory/backends/markdown.ts +283 -0
  70. package/src/memory/backends/sqlite.ts +329 -0
  71. package/src/memory/cache.ts +238 -0
  72. package/src/memory/indexer.ts +238 -0
  73. package/src/memory/manager.ts +572 -0
  74. package/src/terminal/adapters/base.ts +29 -0
  75. package/src/terminal/adapters/native.ts +504 -0
  76. package/src/terminal/adapters/vscode.ts +340 -0
  77. package/src/terminal/manager.ts +308 -0
  78. package/src/terminal/pool.ts +271 -0
  79. package/src/terminal/session.ts +250 -0
  80. package/src/terminal/vscode-bridge.ts +242 -0
  81. package/src/utils/errors.ts +231 -0
  82. package/src/utils/helpers.ts +476 -0
  83. package/src/utils/types.ts +493 -0
@@ -0,0 +1,312 @@
1
+ /**
2
+ * Fixed orchestrator implementation for Claude-Flow
3
+ */
4
+
5
+ import { EventBus } from './event-bus.ts';
6
+ import { Logger } from './logger.ts';
7
+ import { ConfigManager } from './config.ts';
8
+ import { JsonPersistenceManager } from './json-persistence.ts';
9
+
10
+ export interface AgentInfo {
11
+ id: string;
12
+ type: string;
13
+ name: string;
14
+ status: string;
15
+ assignedTasks: string[];
16
+ createdAt: number;
17
+ }
18
+
19
+ export interface TaskInfo {
20
+ id: string;
21
+ type: string;
22
+ description: string;
23
+ status: string;
24
+ progress: number;
25
+ assignedAgent?: string;
26
+ error?: string;
27
+ }
28
+
29
+ export interface SessionInfo {
30
+ id: string;
31
+ type: string;
32
+ agentId: string;
33
+ }
34
+
35
+ export interface WorkflowStatus {
36
+ status: string;
37
+ progress: number;
38
+ error?: string;
39
+ }
40
+
41
+ export interface HealthCheckResult {
42
+ healthy: boolean;
43
+ memory: boolean;
44
+ terminalPool: boolean;
45
+ mcp: boolean;
46
+ }
47
+
48
+ export class Orchestrator {
49
+ private agents: Map<string, AgentInfo> = new Map();
50
+ private tasks: Map<string, TaskInfo> = new Map();
51
+ private sessions: Map<string, SessionInfo> = new Map();
52
+ private persistence: JsonPersistenceManager;
53
+ private workflows: Map<string, WorkflowStatus> = new Map();
54
+ private started = false;
55
+
56
+ constructor(
57
+ private config: ConfigManager,
58
+ private eventBus: EventBus,
59
+ private logger: Logger
60
+ ) {
61
+ this.persistence = new JsonPersistenceManager();
62
+ }
63
+
64
+ async start(): Promise<void> {
65
+ if (this.started) {
66
+ throw new Error('Orchestrator already started');
67
+ }
68
+
69
+ this.logger.info('Starting orchestrator...');
70
+
71
+ // Initialize persistence
72
+ await this.persistence.initialize();
73
+
74
+ // Load existing agents and tasks from database
75
+ await this.loadFromPersistence();
76
+
77
+ // Initialize components
78
+ this.eventBus.emit('system:ready', { timestamp: new Date() });
79
+
80
+ this.started = true;
81
+ this.logger.info('Orchestrator started successfully');
82
+ }
83
+
84
+ private async loadFromPersistence(): Promise<void> {
85
+ // Load agents
86
+ const persistedAgents = await this.persistence.getActiveAgents();
87
+ for (const agent of persistedAgents) {
88
+ this.agents.set(agent.id, {
89
+ id: agent.id,
90
+ type: agent.type,
91
+ name: agent.name,
92
+ status: agent.status,
93
+ assignedTasks: [],
94
+ createdAt: agent.createdAt,
95
+ });
96
+ }
97
+
98
+ // Load tasks
99
+ const persistedTasks = await this.persistence.getActiveTasks();
100
+ for (const task of persistedTasks) {
101
+ this.tasks.set(task.id, {
102
+ id: task.id,
103
+ type: task.type,
104
+ description: task.description,
105
+ status: task.status,
106
+ progress: task.progress,
107
+ assignedAgent: task.assignedAgent,
108
+ error: task.error,
109
+ });
110
+ }
111
+
112
+ this.logger.info(`Loaded ${this.agents.size} agents and ${this.tasks.size} tasks from persistence`);
113
+ }
114
+
115
+ async stop(): Promise<void> {
116
+ if (!this.started) {
117
+ return;
118
+ }
119
+
120
+ this.logger.info('Stopping orchestrator...');
121
+
122
+ // Clean up resources
123
+ this.agents.clear();
124
+ this.tasks.clear();
125
+ this.sessions.clear();
126
+ this.workflows.clear();
127
+
128
+ // Close persistence
129
+ this.persistence.close();
130
+
131
+ this.started = false;
132
+ this.logger.info('Orchestrator stopped');
133
+ }
134
+
135
+ async spawnAgent(profile: {
136
+ type: string;
137
+ name: string;
138
+ capabilities: string[];
139
+ systemPrompt: string;
140
+ maxConcurrentTasks: number;
141
+ priority: number;
142
+ }): Promise<string> {
143
+ const agentId = `agent-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
144
+
145
+ const agent: AgentInfo = {
146
+ id: agentId,
147
+ type: profile.type,
148
+ name: profile.name,
149
+ status: 'active',
150
+ assignedTasks: [],
151
+ createdAt: Date.now(),
152
+ };
153
+
154
+ // Save to persistence
155
+ await this.persistence.saveAgent({
156
+ id: agentId,
157
+ type: profile.type,
158
+ name: profile.name,
159
+ status: 'active',
160
+ capabilities: profile.capabilities,
161
+ systemPrompt: profile.systemPrompt,
162
+ maxConcurrentTasks: profile.maxConcurrentTasks,
163
+ priority: profile.priority,
164
+ createdAt: Date.now(),
165
+ });
166
+
167
+ this.agents.set(agentId, agent);
168
+ this.eventBus.emit('agent:spawned', { agentId, profile });
169
+
170
+ return agentId;
171
+ }
172
+
173
+ async terminateAgent(agentId: string): Promise<void> {
174
+ const agent = this.agents.get(agentId);
175
+ if (!agent) {
176
+ throw new Error(`Agent ${agentId} not found`);
177
+ }
178
+
179
+ // Update persistence
180
+ await this.persistence.updateAgentStatus(agentId, 'terminated');
181
+
182
+ this.agents.delete(agentId);
183
+ this.eventBus.emit('agent:terminated', { agentId, reason: 'User requested' });
184
+ }
185
+
186
+ getActiveAgents(): AgentInfo[] {
187
+ return Array.from(this.agents.values());
188
+ }
189
+
190
+ getAgentInfo(agentId: string): AgentInfo | undefined {
191
+ return this.agents.get(agentId);
192
+ }
193
+
194
+ async submitTask(task: {
195
+ type: string;
196
+ description: string;
197
+ priority: number;
198
+ dependencies: string[];
199
+ metadata: Record<string, unknown>;
200
+ }): Promise<string> {
201
+ const taskId = `task-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
202
+
203
+ const taskInfo: TaskInfo = {
204
+ id: taskId,
205
+ type: task.type,
206
+ description: task.description,
207
+ status: 'pending',
208
+ progress: 0,
209
+ };
210
+
211
+ // Save to persistence
212
+ await this.persistence.saveTask({
213
+ id: taskId,
214
+ type: task.type,
215
+ description: task.description,
216
+ status: 'pending',
217
+ priority: task.priority,
218
+ dependencies: task.dependencies,
219
+ metadata: task.metadata,
220
+ progress: 0,
221
+ createdAt: Date.now(),
222
+ });
223
+
224
+ this.tasks.set(taskId, taskInfo);
225
+ this.eventBus.emit('task:created', { taskId, task });
226
+
227
+ // Simulate task assignment
228
+ const availableAgents = Array.from(this.agents.values()).filter(a => a.status === 'active');
229
+ if (availableAgents.length > 0) {
230
+ const agent = availableAgents[0];
231
+ taskInfo.assignedAgent = agent.id;
232
+ taskInfo.status = 'assigned';
233
+ agent.assignedTasks.push(taskId);
234
+ this.eventBus.emit('task:assigned', { taskId, agentId: agent.id });
235
+
236
+ // Update persistence with assignment
237
+ await this.persistence.updateTaskStatus(taskId, 'assigned', agent.id);
238
+ }
239
+
240
+ return taskId;
241
+ }
242
+
243
+ getTaskQueue(): TaskInfo[] {
244
+ return Array.from(this.tasks.values());
245
+ }
246
+
247
+ getTaskStatus(taskId: string): TaskInfo | undefined {
248
+ return this.tasks.get(taskId);
249
+ }
250
+
251
+ async cancelTask(taskId: string): Promise<void> {
252
+ const task = this.tasks.get(taskId);
253
+ if (!task) {
254
+ throw new Error(`Task ${taskId} not found`);
255
+ }
256
+
257
+ task.status = 'cancelled';
258
+ this.eventBus.emit('task:cancelled', { taskId });
259
+ }
260
+
261
+ getActiveSessions(): SessionInfo[] {
262
+ return Array.from(this.sessions.values());
263
+ }
264
+
265
+ async terminateSession(sessionId: string): Promise<void> {
266
+ const session = this.sessions.get(sessionId);
267
+ if (!session) {
268
+ throw new Error(`Session ${sessionId} not found`);
269
+ }
270
+
271
+ this.sessions.delete(sessionId);
272
+ this.eventBus.emit('session:terminated', { sessionId });
273
+ }
274
+
275
+ async executeWorkflow(workflow: any): Promise<string> {
276
+ const workflowId = `workflow-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
277
+
278
+ const status: WorkflowStatus = {
279
+ status: 'running',
280
+ progress: 0,
281
+ };
282
+
283
+ this.workflows.set(workflowId, status);
284
+ this.eventBus.emit('workflow:started', { workflowId, workflow });
285
+
286
+ // Simulate workflow execution
287
+ setTimeout(() => {
288
+ status.status = 'completed';
289
+ status.progress = 100;
290
+ this.eventBus.emit('workflow:completed', { workflowId });
291
+ }, 5000);
292
+
293
+ return workflowId;
294
+ }
295
+
296
+ async getWorkflowStatus(workflowId: string): Promise<WorkflowStatus> {
297
+ const status = this.workflows.get(workflowId);
298
+ if (!status) {
299
+ throw new Error(`Workflow ${workflowId} not found`);
300
+ }
301
+ return status;
302
+ }
303
+
304
+ async healthCheck(): Promise<HealthCheckResult> {
305
+ return {
306
+ healthy: this.started,
307
+ memory: true,
308
+ terminalPool: true,
309
+ mcp: this.started,
310
+ };
311
+ }
312
+ }