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,310 @@
1
+ /**
2
+ * Output formatting utilities for CLI
3
+ */
4
+
5
+ import { colors } from '@cliffy/ansi/colors';
6
+ import { Table } from '@cliffy/table';
7
+ // Box is not available in the current cliffy version
8
+ import { AgentProfile, Task, MemoryEntry, HealthStatus } from '../utils/types.ts';
9
+
10
+ /**
11
+ * Formats an error for display
12
+ */
13
+ export function formatError(error: unknown): string {
14
+ if (error instanceof Error) {
15
+ let message = error.message;
16
+
17
+ if ('code' in error) {
18
+ message = `[${(error as any).code}] ${message}`;
19
+ }
20
+
21
+ if ('details' in error && (error as any).details) {
22
+ message += '\n' + colors.gray('Details: ' + JSON.stringify((error as any).details, null, 2));
23
+ }
24
+
25
+ return message;
26
+ }
27
+
28
+ return String(error);
29
+ }
30
+
31
+ /**
32
+ * Formats an agent profile for display
33
+ */
34
+ export function formatAgent(agent: AgentProfile): string {
35
+ const lines = [
36
+ colors.cyan.bold(`Agent: ${agent.name}`),
37
+ colors.gray(`ID: ${agent.id}`),
38
+ colors.gray(`Type: ${agent.type}`),
39
+ colors.gray(`Priority: ${agent.priority}`),
40
+ colors.gray(`Max Tasks: ${agent.maxConcurrentTasks}`),
41
+ colors.gray(`Capabilities: ${agent.capabilities.join(', ')}`),
42
+ ];
43
+
44
+ return lines.join('\n');
45
+ }
46
+
47
+ /**
48
+ * Formats a task for display
49
+ */
50
+ export function formatTask(task: Task): string {
51
+ const statusColor = {
52
+ pending: colors.gray,
53
+ queued: colors.yellow,
54
+ assigned: colors.blue,
55
+ running: colors.cyan,
56
+ completed: colors.green,
57
+ failed: colors.red,
58
+ cancelled: colors.magenta,
59
+ }[task.status] || colors.white;
60
+
61
+ const lines = [
62
+ colors.yellow.bold(`Task: ${task.description}`),
63
+ colors.gray(`ID: ${task.id}`),
64
+ colors.gray(`Type: ${task.type}`),
65
+ statusColor(`Status: ${task.status}`),
66
+ colors.gray(`Priority: ${task.priority}`),
67
+ ];
68
+
69
+ if (task.assignedAgent) {
70
+ lines.push(colors.gray(`Assigned to: ${task.assignedAgent}`));
71
+ }
72
+
73
+ if (task.dependencies.length > 0) {
74
+ lines.push(colors.gray(`Dependencies: ${task.dependencies.join(', ')}`));
75
+ }
76
+
77
+ if (task.error) {
78
+ lines.push(colors.red(`Error: ${task.error.message}`));
79
+ }
80
+
81
+ return lines.join('\n');
82
+ }
83
+
84
+ /**
85
+ * Formats a memory entry for display
86
+ */
87
+ export function formatMemoryEntry(entry: MemoryEntry): string {
88
+ const lines = [
89
+ colors.magenta.bold(`Memory Entry: ${entry.type}`),
90
+ colors.gray(`ID: ${entry.id}`),
91
+ colors.gray(`Agent: ${entry.agentId}`),
92
+ colors.gray(`Session: ${entry.sessionId}`),
93
+ colors.gray(`Timestamp: ${entry.timestamp.toISOString()}`),
94
+ colors.gray(`Version: ${entry.version}`),
95
+ ];
96
+
97
+ if (entry.tags.length > 0) {
98
+ lines.push(colors.gray(`Tags: ${entry.tags.join(', ')}`));
99
+ }
100
+
101
+ lines.push('', colors.white('Content:'), entry.content);
102
+
103
+ return lines.join('\n');
104
+ }
105
+
106
+ /**
107
+ * Formats health status for display
108
+ */
109
+ export function formatHealthStatus(health: HealthStatus): string {
110
+ const statusColor = {
111
+ healthy: colors.green,
112
+ degraded: colors.yellow,
113
+ unhealthy: colors.red,
114
+ }[health.status];
115
+
116
+ const lines = [
117
+ statusColor.bold(`System Status: ${health.status.toUpperCase()}`),
118
+ colors.gray(`Checked at: ${health.timestamp.toISOString()}`),
119
+ '',
120
+ colors.cyan.bold('Components:'),
121
+ ];
122
+
123
+ for (const [name, component] of Object.entries(health.components)) {
124
+ const compColor = {
125
+ healthy: colors.green,
126
+ degraded: colors.yellow,
127
+ unhealthy: colors.red,
128
+ }[component.status];
129
+
130
+ lines.push(compColor(` ${name}: ${component.status}`));
131
+
132
+ if (component.error) {
133
+ lines.push(colors.red(` Error: ${component.error}`));
134
+ }
135
+
136
+ if (component.metrics) {
137
+ for (const [metric, value] of Object.entries(component.metrics)) {
138
+ lines.push(colors.gray(` ${metric}: ${value}`));
139
+ }
140
+ }
141
+ }
142
+
143
+ return lines.join('\n');
144
+ }
145
+
146
+ /**
147
+ * Creates a table for agent listing
148
+ */
149
+ export function createAgentTable(agents: AgentProfile[]): Table {
150
+ const table = new Table()
151
+ .header(['ID', 'Name', 'Type', 'Priority', 'Max Tasks'])
152
+ .border(true);
153
+
154
+ for (const agent of agents) {
155
+ table.push([
156
+ agent.id,
157
+ agent.name,
158
+ agent.type,
159
+ agent.priority.toString(),
160
+ agent.maxConcurrentTasks.toString(),
161
+ ]);
162
+ }
163
+
164
+ return table;
165
+ }
166
+
167
+ /**
168
+ * Creates a table for task listing
169
+ */
170
+ export function createTaskTable(tasks: Task[]): Table {
171
+ const table = new Table()
172
+ .header(['ID', 'Type', 'Description', 'Status', 'Agent'])
173
+ .border(true);
174
+
175
+ for (const task of tasks) {
176
+ const statusCell = {
177
+ pending: colors.gray(task.status),
178
+ queued: colors.yellow(task.status),
179
+ assigned: colors.blue(task.status),
180
+ running: colors.cyan(task.status),
181
+ completed: colors.green(task.status),
182
+ failed: colors.red(task.status),
183
+ cancelled: colors.magenta(task.status),
184
+ }[task.status] || task.status;
185
+
186
+ table.push([
187
+ task.id,
188
+ task.type,
189
+ task.description.substring(0, 40) + (task.description.length > 40 ? '...' : ''),
190
+ statusCell,
191
+ task.assignedAgent || '-',
192
+ ]);
193
+ }
194
+
195
+ return table;
196
+ }
197
+
198
+ /**
199
+ * Formats duration in human-readable form
200
+ */
201
+ export function formatDuration(ms: number): string {
202
+ if (ms < 1000) {
203
+ return `${ms}ms`;
204
+ }
205
+
206
+ const seconds = Math.floor(ms / 1000);
207
+ const minutes = Math.floor(seconds / 60);
208
+ const hours = Math.floor(minutes / 60);
209
+ const days = Math.floor(hours / 24);
210
+
211
+ if (days > 0) {
212
+ return `${days}d ${hours % 24}h`;
213
+ }
214
+ if (hours > 0) {
215
+ return `${hours}h ${minutes % 60}m`;
216
+ }
217
+ if (minutes > 0) {
218
+ return `${minutes}m ${seconds % 60}s`;
219
+ }
220
+
221
+ return `${seconds}s`;
222
+ }
223
+
224
+ /**
225
+ * Displays the Claude-Flow banner
226
+ */
227
+ export function displayBanner(version: string): void {
228
+ const banner = `
229
+ ${colors.cyan.bold('╔══════════════════════════════════════════════════════════════╗')}
230
+ ${colors.cyan.bold('║')} ${colors.white.bold('🧠 Claude-Flow')} ${colors.gray('v' + version)} ${colors.cyan.bold('║')}
231
+ ${colors.cyan.bold('║')} ${colors.gray('Advanced AI Agent Orchestration')} ${colors.cyan.bold('║')}
232
+ ${colors.cyan.bold('╚══════════════════════════════════════════════════════════════╝')}
233
+ `;
234
+ console.log(banner);
235
+ }
236
+
237
+ /**
238
+ * Displays detailed version information
239
+ */
240
+ export function displayVersion(version: string, buildDate: string): void {
241
+ const info = [
242
+ colors.cyan.bold('Claude-Flow Version Information'),
243
+ '',
244
+ colors.white('Version: ') + colors.yellow(version),
245
+ colors.white('Build Date: ') + colors.yellow(buildDate),
246
+ colors.white('Runtime: ') + colors.yellow('Deno ' + Deno.version.deno),
247
+ colors.white('TypeScript: ') + colors.yellow(Deno.version.typescript),
248
+ colors.white('V8: ') + colors.yellow(Deno.version.v8),
249
+ '',
250
+ colors.gray('Components:'),
251
+ colors.white(' • Multi-Agent Orchestration'),
252
+ colors.white(' • Memory Management'),
253
+ colors.white(' • Terminal Integration'),
254
+ colors.white(' • MCP Server'),
255
+ colors.white(' • Task Coordination'),
256
+ '',
257
+ colors.blue('Homepage: ') + colors.underline('https://github.com/anthropics/claude-code-flow'),
258
+ ];
259
+
260
+ console.log(info.join('\n'));
261
+ }
262
+
263
+ /**
264
+ * Formats a progress bar
265
+ */
266
+ export function formatProgressBar(
267
+ current: number,
268
+ total: number,
269
+ width: number = 40,
270
+ label?: string
271
+ ): string {
272
+ const percentage = Math.min(100, (current / total) * 100);
273
+ const filled = Math.floor((percentage / 100) * width);
274
+ const empty = width - filled;
275
+
276
+ const bar = colors.green('█'.repeat(filled)) + colors.gray('░'.repeat(empty));
277
+ const percent = percentage.toFixed(1).padStart(5) + '%';
278
+
279
+ let result = `[${bar}] ${percent}`;
280
+ if (label) {
281
+ result = `${label}: ${result}`;
282
+ }
283
+
284
+ return result;
285
+ }
286
+
287
+ /**
288
+ * Creates a status indicator
289
+ */
290
+ export function formatStatusIndicator(status: string): string {
291
+ const indicators = {
292
+ success: colors.green('✓'),
293
+ error: colors.red('✗'),
294
+ warning: colors.yellow('⚠'),
295
+ info: colors.blue('ℹ'),
296
+ running: colors.cyan('⟳'),
297
+ pending: colors.gray('○'),
298
+ };
299
+
300
+ return indicators[status as keyof typeof indicators] || status;
301
+ }
302
+
303
+ /**
304
+ * Formats a spinner with message
305
+ */
306
+ export function formatSpinner(message: string, frame: number = 0): string {
307
+ const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
308
+ const spinner = colors.cyan(frames[frame % frames.length]);
309
+ return `${spinner} ${message}`;
310
+ }
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env -S deno run --allow-all
2
+ /**
3
+ * Claude-Flow CLI entry point
4
+ * Advanced AI agent orchestration system
5
+ */
6
+
7
+ import { Command } from '@cliffy/command';
8
+ import { colors } from '@cliffy/ansi/colors';
9
+ // Spinner import removed - not available in current cliffy version
10
+ import { logger } from '../core/logger.ts';
11
+ import { configManager } from '../core/config.ts';
12
+ import { startCommand } from './commands/start.ts';
13
+ import { agentCommand } from './commands/agent.ts';
14
+ import { taskCommand } from './commands/task.ts';
15
+ import { memoryCommand } from './commands/memory.ts';
16
+ import { configCommand } from './commands/config.ts';
17
+ import { statusCommand } from './commands/status.ts';
18
+ import { monitorCommand } from './commands/monitor.ts';
19
+ import { sessionCommand } from './commands/session.ts';
20
+ import { workflowCommand } from './commands/workflow.ts';
21
+ import { helpCommand } from './commands/help.ts';
22
+ import { mcpCommand } from './commands/mcp.ts';
23
+ import { formatError, displayBanner, displayVersion } from './formatter.ts';
24
+ import { startREPL } from './repl.ts';
25
+ import { CompletionGenerator } from './completion.ts';
26
+
27
+ // Version information
28
+ const VERSION = '1.0.0';
29
+ const BUILD_DATE = new Date().toISOString().split('T')[0];
30
+
31
+ // Main CLI command
32
+ const cli = new Command()
33
+ .name('claude-flow')
34
+ .version(VERSION)
35
+ .description('Claude-Flow: Advanced AI agent orchestration system for multi-agent coordination')
36
+ .meta('Build', BUILD_DATE)
37
+ .meta('Runtime', 'Deno')
38
+ .globalOption('-c, --config <path:string>', 'Path to configuration file', {
39
+ default: './claude-flow.config.json',
40
+ })
41
+ .globalOption('-v, --verbose', 'Enable verbose logging')
42
+ .globalOption('-q, --quiet', 'Suppress non-essential output')
43
+ .globalOption('--log-level <level:string>', 'Set log level (debug, info, warn, error)', {
44
+ default: 'info',
45
+ })
46
+ .globalOption('--no-color', 'Disable colored output')
47
+ .globalOption('--json', 'Output in JSON format where applicable')
48
+ .globalOption('--profile <profile:string>', 'Use named configuration profile')
49
+ .action(async (options) => {
50
+ // If no subcommand, show banner and start REPL
51
+ await setupLogging(options);
52
+
53
+ if (!options.quiet) {
54
+ displayBanner(VERSION);
55
+ console.log(colors.gray('Type "help" for available commands or "exit" to quit.\n'));
56
+ }
57
+
58
+ await startREPL(options);
59
+ });
60
+
61
+ // Add subcommands
62
+ cli
63
+ .command('start', startCommand)
64
+ .command('agent', agentCommand)
65
+ .command('task', taskCommand)
66
+ .command('memory', memoryCommand)
67
+ .command('config', configCommand)
68
+ .command('status', statusCommand)
69
+ .command('monitor', monitorCommand)
70
+ .command('session', sessionCommand)
71
+ .command('workflow', workflowCommand)
72
+ .command('mcp', mcpCommand)
73
+ .command('help', helpCommand)
74
+ .command('repl', new Command()
75
+ .description('Start interactive REPL mode with command completion')
76
+ .option('--no-banner', 'Skip welcome banner')
77
+ .option('--history-file <path:string>', 'Custom history file path')
78
+ .action(async (options) => {
79
+ await setupLogging(options);
80
+ if (options.banner !== false) {
81
+ displayBanner(VERSION);
82
+ }
83
+ await startREPL(options);
84
+ }),
85
+ )
86
+ .command('version', new Command()
87
+ .description('Show detailed version information')
88
+ .option('--short', 'Show version number only')
89
+ .action(async (options) => {
90
+ if (options.short) {
91
+ console.log(VERSION);
92
+ } else {
93
+ displayVersion(VERSION, BUILD_DATE);
94
+ }
95
+ }),
96
+ )
97
+ .command('completion', new Command()
98
+ .description('Generate shell completion scripts')
99
+ .arguments('[shell:string]')
100
+ .option('--install', 'Install completion script automatically')
101
+ .action(async (options, shell) => {
102
+ const generator = new CompletionGenerator();
103
+ await generator.generate(shell || 'detect', options.install === true);
104
+ }),
105
+ );
106
+
107
+ // Global error handler
108
+ async function handleError(error: unknown, options?: any): Promise<void> {
109
+ const formatted = formatError(error);
110
+
111
+ if (options?.json) {
112
+ console.error(JSON.stringify({
113
+ error: true,
114
+ message: formatted,
115
+ timestamp: new Date().toISOString(),
116
+ }));
117
+ } else {
118
+ console.error(colors.red(colors.bold('✗ Error:')), formatted);
119
+ }
120
+
121
+ // Show stack trace in debug mode or verbose
122
+ if (Deno.env.get('CLAUDE_FLOW_DEBUG') === 'true' || options?.verbose) {
123
+ console.error(colors.gray('\nStack trace:'));
124
+ console.error(error);
125
+ }
126
+
127
+ // Suggest helpful actions
128
+ if (!options?.quiet) {
129
+ console.error(colors.gray('\nTry running with --verbose for more details'));
130
+ console.error(colors.gray('Or use "claude-flow help" to see available commands'));
131
+ }
132
+
133
+ Deno.exit(1);
134
+ }
135
+
136
+ // Setup logging and configuration based on CLI options
137
+ async function setupLogging(options: any): Promise<void> {
138
+ // Determine log level
139
+ let logLevel = options.logLevel;
140
+ if (options.verbose) logLevel = 'debug';
141
+ if (options.quiet) logLevel = 'warn';
142
+
143
+ // Configure logger
144
+ await logger.configure({
145
+ level: logLevel as any,
146
+ format: options.json ? 'json' : 'text',
147
+ destination: 'console',
148
+ });
149
+
150
+ // Load configuration
151
+ try {
152
+ if (options.config) {
153
+ await configManager.load(options.config);
154
+ } else {
155
+ // Try to load default config file if it exists
156
+ try {
157
+ await configManager.load('./claude-flow.config.json');
158
+ } catch {
159
+ // Use default config if no file found
160
+ configManager.loadDefault();
161
+ }
162
+ }
163
+
164
+ // Apply profile if specified
165
+ if (options.profile) {
166
+ await configManager.applyProfile(options.profile);
167
+ }
168
+ } catch (error) {
169
+ logger.warn('Failed to load configuration:', (error as Error).message);
170
+ configManager.loadDefault();
171
+ }
172
+ }
173
+
174
+ // Signal handlers for graceful shutdown
175
+ function setupSignalHandlers(): void {
176
+ const gracefulShutdown = () => {
177
+ console.log('\n' + colors.gray('Gracefully shutting down...'));
178
+ Deno.exit(0);
179
+ };
180
+
181
+ Deno.addSignalListener('SIGINT', gracefulShutdown);
182
+ Deno.addSignalListener('SIGTERM', gracefulShutdown);
183
+ }
184
+
185
+ // Main entry point
186
+ if (import.meta.main) {
187
+ let globalOptions: any = {};
188
+
189
+ try {
190
+ // Setup signal handlers
191
+ setupSignalHandlers();
192
+
193
+ // Pre-parse global options for error handling
194
+ const args = Deno.args;
195
+ globalOptions = {
196
+ verbose: args.includes('-v') || args.includes('--verbose'),
197
+ quiet: args.includes('-q') || args.includes('--quiet'),
198
+ json: args.includes('--json'),
199
+ noColor: args.includes('--no-color'),
200
+ };
201
+
202
+ // Configure colors based on options
203
+ if (globalOptions.noColor) {
204
+ colors.setColorEnabled(false);
205
+ }
206
+
207
+ await cli.parse(args);
208
+ } catch (error) {
209
+ await handleError(error, globalOptions);
210
+ }
211
+ }
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env -S deno run --allow-all
2
+ /**
3
+ * Claude-Flow CLI - Main entry point
4
+ */
5
+
6
+ import { CLI } from "./cli-core.ts";
7
+ import { setupCommands } from "./commands/index.ts";
8
+
9
+ const VERSION = "1.0.0";
10
+
11
+ async function main() {
12
+ const cli = new CLI("claude-flow", "Advanced AI Agent Orchestration System");
13
+
14
+ // Setup all commands
15
+ setupCommands(cli);
16
+
17
+ // Run the CLI
18
+ await cli.run();
19
+ }
20
+
21
+ if (import.meta.main) {
22
+ await main();
23
+ }