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,242 @@
1
+ /**
2
+ * VSCode Extension Bridge for Terminal Integration
3
+ *
4
+ * This file provides the bridge between Claude-Flow and VSCode extension API
5
+ * for terminal management and output capture.
6
+ */
7
+
8
+ import * as vscode from 'vscode';
9
+
10
+ /**
11
+ * Terminal output processors registry
12
+ */
13
+ const terminalOutputProcessors = new Map<string, (data: string) => void>();
14
+
15
+ /**
16
+ * Active terminals registry
17
+ */
18
+ const activeTerminals = new Map<string, vscode.Terminal>();
19
+
20
+ /**
21
+ * Terminal write emulators for output capture
22
+ */
23
+ const terminalWriteEmulators = new Map<vscode.Terminal, vscode.EventEmitter<string>>();
24
+
25
+ /**
26
+ * Initialize the VSCode terminal bridge
27
+ */
28
+ export function initializeTerminalBridge(context: vscode.ExtensionContext): void {
29
+ // Inject VSCode API into global scope for Claude-Flow
30
+ (globalThis as any).vscode = vscode;
31
+
32
+ // Register terminal output processor function
33
+ (globalThis as any).registerTerminalOutputProcessor = (
34
+ terminalId: string,
35
+ processor: (data: string) => void
36
+ ) => {
37
+ terminalOutputProcessors.set(terminalId, processor);
38
+ };
39
+
40
+ // Override terminal creation to capture output
41
+ const originalCreateTerminal = vscode.window.createTerminal;
42
+ (vscode.window as any).createTerminal = function(options: vscode.TerminalOptions) {
43
+ const terminal = originalCreateTerminal.call(vscode.window, options) as vscode.Terminal;
44
+
45
+ // Create write emulator for this terminal
46
+ const writeEmulator = new vscode.EventEmitter<string>();
47
+ terminalWriteEmulators.set(terminal, writeEmulator);
48
+
49
+ // Find terminal ID from name
50
+ const match = options.name?.match(/Claude-Flow Terminal ([\w-]+)/);
51
+ if (match) {
52
+ const terminalId = match[1];
53
+ activeTerminals.set(terminalId, terminal);
54
+
55
+ // Set up output capture
56
+ captureTerminalOutput(terminal, terminalId);
57
+ }
58
+
59
+ return terminal;
60
+ };
61
+
62
+ // Clean up on terminal close
63
+ context.subscriptions.push(
64
+ vscode.window.onDidCloseTerminal((terminal: vscode.Terminal) => {
65
+ // Find and remove from registries
66
+ for (const [id, term] of activeTerminals.entries()) {
67
+ if (term === terminal) {
68
+ activeTerminals.delete(id);
69
+ terminalOutputProcessors.delete(id);
70
+ break;
71
+ }
72
+ }
73
+
74
+ // Clean up write emulator
75
+ const emulator = terminalWriteEmulators.get(terminal);
76
+ if (emulator) {
77
+ emulator.dispose();
78
+ terminalWriteEmulators.delete(terminal);
79
+ }
80
+ })
81
+ );
82
+ }
83
+
84
+ /**
85
+ * Capture terminal output using various methods
86
+ */
87
+ function captureTerminalOutput(terminal: vscode.Terminal, terminalId: string): void {
88
+ // Method 1: Use terminal.sendText override to capture commands
89
+ const originalSendText = terminal.sendText;
90
+ (terminal as any).sendText = function(text: string, addNewLine?: boolean) {
91
+ // Call original method
92
+ originalSendText.call(terminal, text, addNewLine);
93
+
94
+ // Process command
95
+ const processor = terminalOutputProcessors.get(terminalId);
96
+ if (processor && text) {
97
+ // Simulate command echo
98
+ processor(text + (addNewLine !== false ? '\n' : ''));
99
+ }
100
+ };
101
+
102
+ // Method 2: Use proposed API if available
103
+ if ('onDidWriteData' in terminal) {
104
+ const writeDataEvent = (terminal as any).onDidWriteData;
105
+ if (writeDataEvent) {
106
+ writeDataEvent((data: string) => {
107
+ const processor = terminalOutputProcessors.get(terminalId);
108
+ if (processor) {
109
+ processor(data);
110
+ }
111
+ });
112
+ }
113
+ }
114
+
115
+ // Method 3: Use terminal renderer if available
116
+ setupTerminalRenderer(terminal, terminalId);
117
+ }
118
+
119
+ /**
120
+ * Set up terminal renderer for output capture
121
+ */
122
+ function setupTerminalRenderer(terminal: vscode.Terminal, terminalId: string): void {
123
+ // Check if terminal renderer API is available
124
+ if (vscode.window.registerTerminalProfileProvider) {
125
+ // This is a more advanced method that requires additional setup
126
+ // It would involve creating a custom terminal profile that captures output
127
+
128
+ // For now, we'll use a simpler approach with periodic output checking
129
+ let lastOutput = '';
130
+ const checkOutput = setInterval(() => {
131
+ // This is a placeholder - actual implementation would depend on
132
+ // available VSCode APIs for reading terminal content
133
+
134
+ // Check if terminal is still active
135
+ if (!activeTerminals.has(terminalId)) {
136
+ clearInterval(checkOutput);
137
+ }
138
+ }, 100);
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Create a terminal with output capture
144
+ */
145
+ export async function createCapturedTerminal(
146
+ name: string,
147
+ shellPath?: string,
148
+ shellArgs?: string[]
149
+ ): Promise<{
150
+ terminal: vscode.Terminal;
151
+ onData: vscode.Event<string>;
152
+ }> {
153
+ const writeEmulator = new vscode.EventEmitter<string>();
154
+
155
+ const terminal = vscode.window.createTerminal({
156
+ name,
157
+ shellPath,
158
+ shellArgs,
159
+ });
160
+
161
+ terminalWriteEmulators.set(terminal, writeEmulator);
162
+
163
+ return {
164
+ terminal,
165
+ onData: writeEmulator.event,
166
+ };
167
+ }
168
+
169
+ /**
170
+ * Send command to terminal and capture output
171
+ */
172
+ export async function executeTerminalCommand(
173
+ terminal: vscode.Terminal,
174
+ command: string,
175
+ timeout: number = 30000
176
+ ): Promise<string> {
177
+ return new Promise((resolve, reject) => {
178
+ const writeEmulator = terminalWriteEmulators.get(terminal);
179
+ if (!writeEmulator) {
180
+ reject(new Error('No write emulator for terminal'));
181
+ return;
182
+ }
183
+
184
+ let output = '';
185
+ const marker = `__COMMAND_COMPLETE_${Date.now()}__`;
186
+
187
+ // Set up output listener
188
+ const disposable = writeEmulator.event((data: string) => {
189
+ output += data;
190
+
191
+ if (output.includes(marker)) {
192
+ // Command completed
193
+ disposable.dispose();
194
+ const result = output.substring(0, output.indexOf(marker));
195
+ resolve(result);
196
+ }
197
+ });
198
+
199
+ // Set timeout
200
+ const timer = setTimeout(() => {
201
+ disposable.dispose();
202
+ reject(new Error('Command timeout'));
203
+ }, timeout);
204
+
205
+ // Execute command with marker
206
+ terminal.sendText(`${command} && echo "${marker}"`);
207
+
208
+ // Clear timeout on success
209
+ writeEmulator.event(() => {
210
+ if (output.includes(marker)) {
211
+ clearTimeout(timer);
212
+ }
213
+ });
214
+ });
215
+ }
216
+
217
+ /**
218
+ * Get terminal by ID
219
+ */
220
+ export function getTerminalById(terminalId: string): vscode.Terminal | undefined {
221
+ return activeTerminals.get(terminalId);
222
+ }
223
+
224
+ /**
225
+ * Dispose all terminal resources
226
+ */
227
+ export function disposeTerminalBridge(): void {
228
+ // Clean up all terminals
229
+ for (const terminal of activeTerminals.values()) {
230
+ terminal.dispose();
231
+ }
232
+ activeTerminals.clear();
233
+
234
+ // Clean up processors
235
+ terminalOutputProcessors.clear();
236
+
237
+ // Clean up write emulators
238
+ for (const emulator of terminalWriteEmulators.values()) {
239
+ emulator.dispose();
240
+ }
241
+ terminalWriteEmulators.clear();
242
+ }
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Custom error types for Claude-Flow
3
+ */
4
+
5
+ /**
6
+ * Base error class for all Claude-Flow errors
7
+ */
8
+ export class ClaudeFlowError extends Error {
9
+ constructor(
10
+ message: string,
11
+ public readonly code: string,
12
+ public readonly details?: unknown,
13
+ ) {
14
+ super(message);
15
+ this.name = 'ClaudeFlowError';
16
+ Error.captureStackTrace(this, this.constructor);
17
+ }
18
+
19
+ toJSON() {
20
+ return {
21
+ name: this.name,
22
+ message: this.message,
23
+ code: this.code,
24
+ details: this.details,
25
+ stack: this.stack,
26
+ };
27
+ }
28
+ }
29
+
30
+ /**
31
+ * Terminal-related errors
32
+ */
33
+ export class TerminalError extends ClaudeFlowError {
34
+ constructor(message: string, details?: unknown) {
35
+ super(message, 'TERMINAL_ERROR', details);
36
+ this.name = 'TerminalError';
37
+ }
38
+ }
39
+
40
+ export class TerminalSpawnError extends TerminalError {
41
+ override readonly code = 'TERMINAL_SPAWN_ERROR';
42
+
43
+ constructor(message: string, details?: unknown) {
44
+ super(message, details);
45
+ }
46
+ }
47
+
48
+ export class TerminalCommandError extends TerminalError {
49
+ override readonly code = 'TERMINAL_COMMAND_ERROR';
50
+
51
+ constructor(message: string, details?: unknown) {
52
+ super(message, details);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Memory-related errors
58
+ */
59
+ export class MemoryError extends ClaudeFlowError {
60
+ constructor(message: string, details?: unknown) {
61
+ super(message, 'MEMORY_ERROR', details);
62
+ this.name = 'MemoryError';
63
+ }
64
+ }
65
+
66
+ export class MemoryBackendError extends MemoryError {
67
+ override readonly code = 'MEMORY_BACKEND_ERROR';
68
+
69
+ constructor(message: string, details?: unknown) {
70
+ super(message, details);
71
+ }
72
+ }
73
+
74
+ export class MemoryConflictError extends MemoryError {
75
+ override readonly code = 'MEMORY_CONFLICT_ERROR';
76
+
77
+ constructor(message: string, details?: unknown) {
78
+ super(message, details);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Coordination-related errors
84
+ */
85
+ export class CoordinationError extends ClaudeFlowError {
86
+ constructor(message: string, details?: unknown) {
87
+ super(message, 'COORDINATION_ERROR', details);
88
+ this.name = 'CoordinationError';
89
+ }
90
+ }
91
+
92
+ export class DeadlockError extends CoordinationError {
93
+ override readonly code = 'DEADLOCK_ERROR';
94
+
95
+ constructor(
96
+ message: string,
97
+ public readonly agents: string[],
98
+ public readonly resources: string[],
99
+ ) {
100
+ super(message, { agents, resources });
101
+ }
102
+ }
103
+
104
+ export class ResourceLockError extends CoordinationError {
105
+ override readonly code = 'RESOURCE_LOCK_ERROR';
106
+
107
+ constructor(message: string, details?: unknown) {
108
+ super(message, details);
109
+ }
110
+ }
111
+
112
+ /**
113
+ * MCP-related errors
114
+ */
115
+ export class MCPError extends ClaudeFlowError {
116
+ constructor(message: string, details?: unknown) {
117
+ super(message, 'MCP_ERROR', details);
118
+ this.name = 'MCPError';
119
+ }
120
+ }
121
+
122
+ export class MCPTransportError extends MCPError {
123
+ override readonly code = 'MCP_TRANSPORT_ERROR';
124
+
125
+ constructor(message: string, details?: unknown) {
126
+ super(message, details);
127
+ }
128
+ }
129
+
130
+ export class MCPMethodNotFoundError extends MCPError {
131
+ override readonly code = 'MCP_METHOD_NOT_FOUND';
132
+
133
+ constructor(method: string) {
134
+ super(`Method not found: ${method}`, { method });
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Configuration errors
140
+ */
141
+ export class ConfigError extends ClaudeFlowError {
142
+ constructor(message: string, details?: unknown) {
143
+ super(message, 'CONFIG_ERROR', details);
144
+ this.name = 'ConfigError';
145
+ }
146
+ }
147
+
148
+ export class ValidationError extends ConfigError {
149
+ override readonly code = 'VALIDATION_ERROR';
150
+
151
+ constructor(message: string, details?: unknown) {
152
+ super(message, details);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Task-related errors
158
+ */
159
+ export class TaskError extends ClaudeFlowError {
160
+ constructor(message: string, details?: unknown) {
161
+ super(message, 'TASK_ERROR', details);
162
+ this.name = 'TaskError';
163
+ }
164
+ }
165
+
166
+ export class TaskTimeoutError extends TaskError {
167
+ override readonly code = 'TASK_TIMEOUT_ERROR';
168
+
169
+ constructor(taskId: string, timeout: number) {
170
+ super(`Task ${taskId} timed out after ${timeout}ms`, { taskId, timeout });
171
+ }
172
+ }
173
+
174
+ export class TaskDependencyError extends TaskError {
175
+ override readonly code = 'TASK_DEPENDENCY_ERROR';
176
+
177
+ constructor(taskId: string, dependencies: string[]) {
178
+ super(`Task ${taskId} has unmet dependencies`, { taskId, dependencies });
179
+ }
180
+ }
181
+
182
+ /**
183
+ * System errors
184
+ */
185
+ export class SystemError extends ClaudeFlowError {
186
+ constructor(message: string, details?: unknown) {
187
+ super(message, 'SYSTEM_ERROR', details);
188
+ this.name = 'SystemError';
189
+ }
190
+ }
191
+
192
+ export class InitializationError extends SystemError {
193
+ override readonly code = 'INITIALIZATION_ERROR';
194
+
195
+ constructor(componentOrMessage: string, details?: unknown) {
196
+ // If the message already contains the word "initialize", use it as-is
197
+ const message = componentOrMessage.includes('initialize')
198
+ ? componentOrMessage
199
+ : `Failed to initialize ${componentOrMessage}`;
200
+ super(message, details ? { component: componentOrMessage, ...details } : { component: componentOrMessage });
201
+ }
202
+ }
203
+
204
+ export class ShutdownError extends SystemError {
205
+ override readonly code = 'SHUTDOWN_ERROR';
206
+
207
+ constructor(message: string, details?: unknown) {
208
+ super(message, details);
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Error utilities
214
+ */
215
+ export function isClaudeFlowError(error: unknown): error is ClaudeFlowError {
216
+ return error instanceof ClaudeFlowError;
217
+ }
218
+
219
+ export function formatError(error: unknown): string {
220
+ if (error instanceof Error) {
221
+ return `${error.name}: ${error.message}`;
222
+ }
223
+ return String(error);
224
+ }
225
+
226
+ export function getErrorDetails(error: unknown): unknown {
227
+ if (isClaudeFlowError(error)) {
228
+ return error.details;
229
+ }
230
+ return undefined;
231
+ }