claude-flow 1.0.6 → 1.0.7

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.
@@ -0,0 +1,589 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Pure Node.js CLI for Claude-Flow
4
+ * This version works without Deno dependency
5
+ */
6
+
7
+ const fs = require('fs').promises;
8
+ const path = require('path');
9
+ const { spawn } = require('child_process');
10
+
11
+ const VERSION = '1.0.0';
12
+
13
+ // ANSI color codes
14
+ const colors = {
15
+ reset: '\x1b[0m',
16
+ bright: '\x1b[1m',
17
+ red: '\x1b[31m',
18
+ green: '\x1b[32m',
19
+ yellow: '\x1b[33m',
20
+ blue: '\x1b[34m',
21
+ cyan: '\x1b[36m',
22
+ };
23
+
24
+ function success(msg) {
25
+ console.log(`${colors.green}✅ ${msg}${colors.reset}`);
26
+ }
27
+
28
+ function error(msg) {
29
+ console.log(`${colors.red}❌ ${msg}${colors.reset}`);
30
+ }
31
+
32
+ function warning(msg) {
33
+ console.log(`${colors.yellow}⚠️ ${msg}${colors.reset}`);
34
+ }
35
+
36
+ function info(msg) {
37
+ console.log(`${colors.blue}ℹ️ ${msg}${colors.reset}`);
38
+ }
39
+
40
+ function printHelp() {
41
+ console.log(`
42
+ ${colors.blue}🧠 Claude-Flow v${VERSION}${colors.reset} - Advanced AI Agent Orchestration System
43
+
44
+ USAGE:
45
+ claude-flow [COMMAND] [OPTIONS]
46
+
47
+ COMMANDS:
48
+ ${colors.cyan}init${colors.reset} Initialize Claude Code integration files
49
+ ${colors.cyan}start${colors.reset} Start the orchestration system
50
+ ${colors.cyan}agent${colors.reset} Manage agents (spawn, list, terminate, info)
51
+ ${colors.cyan}task${colors.reset} Manage tasks (create, list, status, cancel, workflow)
52
+ ${colors.cyan}memory${colors.reset} Manage memory (query, export, import, stats, cleanup)
53
+ ${colors.cyan}config${colors.reset} Manage configuration (show, get, set, init, validate)
54
+ ${colors.cyan}status${colors.reset} Show system status
55
+ ${colors.cyan}monitor${colors.reset} Monitor system in real-time
56
+ ${colors.cyan}mcp${colors.reset} MCP server management (status, tools, config, logs)
57
+ ${colors.cyan}claude${colors.reset} Spawn Claude instances with specific configurations
58
+ ${colors.cyan}session${colors.reset} Manage terminal sessions
59
+ ${colors.cyan}workflow${colors.reset} Execute workflow files
60
+ ${colors.cyan}version${colors.reset} Show version information
61
+ ${colors.cyan}help${colors.reset} Show this help message
62
+
63
+ GLOBAL OPTIONS:
64
+ -c, --config <path> Path to configuration file
65
+ -v, --verbose Enable verbose logging
66
+ --log-level <level> Set log level (debug, info, warn, error)
67
+ --help Show help for specific command
68
+
69
+ EXAMPLES:
70
+ claude-flow init # Initialize project
71
+ claude-flow start # Start orchestrator
72
+ claude-flow agent spawn researcher --name "Bot" # Spawn research agent
73
+ claude-flow task create research "Analyze data" # Create task
74
+ claude-flow status # Show system status
75
+
76
+ Documentation: https://github.com/ruvnet/claude-code-flow
77
+ `);
78
+ }
79
+
80
+ async function executeInit(args) {
81
+ const force = args.includes('-f') || args.includes('--force');
82
+ const minimal = args.includes('-m') || args.includes('--minimal');
83
+
84
+ success('Initializing Claude Code integration files...');
85
+
86
+ try {
87
+ // Check if files already exist
88
+ const files = ['CLAUDE.md', 'memory-bank.md', 'coordination.md'];
89
+ const existingFiles = [];
90
+
91
+ for (const file of files) {
92
+ try {
93
+ await fs.access(file);
94
+ existingFiles.push(file);
95
+ } catch {
96
+ // File doesn't exist, which is fine
97
+ }
98
+ }
99
+
100
+ if (existingFiles.length > 0 && !force) {
101
+ warning(`The following files already exist: ${existingFiles.join(', ')}`);
102
+ console.log('Use --force to overwrite existing files');
103
+ return;
104
+ }
105
+
106
+ // Create CLAUDE.md
107
+ const claudeMd = minimal ? createMinimalClaudeMd() : createFullClaudeMd();
108
+ await fs.writeFile('CLAUDE.md', claudeMd);
109
+ console.log(' ✓ Created CLAUDE.md');
110
+
111
+ // Create memory-bank.md
112
+ const memoryBankMd = minimal ? createMinimalMemoryBankMd() : createFullMemoryBankMd();
113
+ await fs.writeFile('memory-bank.md', memoryBankMd);
114
+ console.log(' ✓ Created memory-bank.md');
115
+
116
+ // Create coordination.md
117
+ const coordinationMd = minimal ? createMinimalCoordinationMd() : createFullCoordinationMd();
118
+ await fs.writeFile('coordination.md', coordinationMd);
119
+ console.log(' ✓ Created coordination.md');
120
+
121
+ // Create directory structure
122
+ const directories = [
123
+ 'memory',
124
+ 'memory/agents',
125
+ 'memory/sessions',
126
+ 'coordination',
127
+ 'coordination/memory_bank',
128
+ 'coordination/subtasks',
129
+ 'coordination/orchestration'
130
+ ];
131
+
132
+ for (const dir of directories) {
133
+ try {
134
+ await fs.mkdir(dir, { recursive: true });
135
+ console.log(` ✓ Created ${dir}/ directory`);
136
+ } catch (err) {
137
+ if (err.code !== 'EEXIST') {
138
+ throw err;
139
+ }
140
+ }
141
+ }
142
+
143
+ // Create placeholder files
144
+ const agentsReadme = createAgentsReadme();
145
+ await fs.writeFile('memory/agents/README.md', agentsReadme);
146
+ console.log(' ✓ Created memory/agents/README.md');
147
+
148
+ const sessionsReadme = createSessionsReadme();
149
+ await fs.writeFile('memory/sessions/README.md', sessionsReadme);
150
+ console.log(' ✓ Created memory/sessions/README.md');
151
+
152
+ // Initialize persistence database
153
+ const initialData = {
154
+ agents: [],
155
+ tasks: [],
156
+ lastUpdated: Date.now()
157
+ };
158
+ await fs.writeFile('memory/claude-flow-data.json', JSON.stringify(initialData, null, 2));
159
+ console.log(' ✓ Created memory/claude-flow-data.json (persistence database)');
160
+
161
+ success('Claude Code integration files initialized successfully!');
162
+ console.log('\nNext steps:');
163
+ console.log('1. Review and customize the generated files for your project');
164
+ console.log('2. Run \'npx claude-flow start\' to begin the orchestration system');
165
+ console.log('3. Use \'claude --dangerously-skip-permissions\' for unattended operation');
166
+
167
+ } catch (err) {
168
+ error(`Failed to initialize files: ${err.message}`);
169
+ process.exit(1);
170
+ }
171
+ }
172
+
173
+ async function executeStatus() {
174
+ try {
175
+ // Check if persistence file exists
176
+ let data;
177
+ try {
178
+ const content = await fs.readFile('memory/claude-flow-data.json', 'utf8');
179
+ data = JSON.parse(content);
180
+ } catch {
181
+ data = { agents: [], tasks: [] };
182
+ }
183
+
184
+ // Check if orchestrator is running (simplified check)
185
+ let isRunning = false;
186
+ try {
187
+ await fs.access('orchestrator.log');
188
+ isRunning = true;
189
+ } catch {
190
+ // Log file doesn't exist, orchestrator not running
191
+ }
192
+
193
+ const activeAgents = data.agents.filter(a => a.status === 'active').length;
194
+ const totalAgents = data.agents.length;
195
+ const pendingTasks = data.tasks.filter(t => t.status === 'pending' || t.status === 'assigned').length;
196
+ const totalTasks = data.tasks.length;
197
+ const completedTasks = data.tasks.filter(t => t.status === 'completed').length;
198
+
199
+ success('Claude-Flow System Status:');
200
+ console.log(`🟢 Status: ${isRunning ? 'Running' : 'Stopped'}`);
201
+ console.log(`🤖 Agents: ${activeAgents} active (${totalAgents} total)`);
202
+ console.log(`📋 Tasks: ${pendingTasks} in queue (${totalTasks} total)`);
203
+ console.log(`✅ Completed: ${completedTasks} tasks`);
204
+ console.log(`💾 Memory: Ready`);
205
+ console.log(`🖥️ Terminal Pool: Ready`);
206
+ console.log(`🌐 MCP Server: ${isRunning ? 'Running' : 'Stopped'}`);
207
+
208
+ } catch (err) {
209
+ error(`Failed to get status: ${err.message}`);
210
+ }
211
+ }
212
+
213
+ // Template functions
214
+ function createMinimalClaudeMd() {
215
+ return `# Claude Code Configuration
216
+
217
+ ## Build Commands
218
+ - \`npm run build\`: Build the project
219
+ - \`npm run test\`: Run tests
220
+ - \`npm run lint\`: Run linter
221
+
222
+ ## Code Style
223
+ - Use TypeScript/ES modules
224
+ - Follow project conventions
225
+ - Run typecheck before committing
226
+
227
+ ## Project Info
228
+ This is a Claude-Flow AI agent orchestration system.
229
+ `;
230
+ }
231
+
232
+ function createFullClaudeMd() {
233
+ return `# Claude Code Configuration
234
+
235
+ ## Build Commands
236
+ - \`npm run build\`: Build the project using Deno compile
237
+ - \`npm run test\`: Run the full test suite
238
+ - \`npm run lint\`: Run ESLint and format checks
239
+ - \`npm run typecheck\`: Run TypeScript type checking
240
+ - \`npx claude-flow start\`: Start the orchestration system
241
+ - \`npx claude-flow --help\`: Show all available commands
242
+
243
+ ## Code Style Preferences
244
+ - Use ES modules (import/export) syntax, not CommonJS (require)
245
+ - Destructure imports when possible (e.g., \`import { foo } from 'bar'\`)
246
+ - Use TypeScript for all new code
247
+ - Follow existing naming conventions (camelCase for variables, PascalCase for classes)
248
+ - Add JSDoc comments for public APIs
249
+ - Use async/await instead of Promise chains
250
+ - Prefer const/let over var
251
+
252
+ ## Workflow Guidelines
253
+ - Always run typecheck after making code changes
254
+ - Run tests before committing changes
255
+ - Use meaningful commit messages following conventional commits
256
+ - Create feature branches for new functionality
257
+ - Ensure all tests pass before merging
258
+
259
+ ## Project Architecture
260
+ This is a Claude-Flow AI agent orchestration system with the following components:
261
+ - **CLI Interface**: Command-line tools for managing the system
262
+ - **Orchestrator**: Core engine for coordinating agents and tasks
263
+ - **Memory System**: Persistent storage and retrieval of information
264
+ - **Terminal Management**: Automated terminal session handling
265
+ - **MCP Integration**: Model Context Protocol server for Claude integration
266
+ - **Agent Coordination**: Multi-agent task distribution and management
267
+
268
+ ## Important Notes
269
+ - Use \`claude --dangerously-skip-permissions\` for unattended operation
270
+ - The system supports both daemon and interactive modes
271
+ - Memory persistence is handled automatically
272
+ - All components are event-driven for scalability
273
+
274
+ ## Debugging
275
+ - Check logs in \`./claude-flow.log\`
276
+ - Use \`npx claude-flow status\` to check system health
277
+ - Monitor with \`npx claude-flow monitor\` for real-time updates
278
+ - Verbose output available with \`--verbose\` flag on most commands
279
+ `;
280
+ }
281
+
282
+ function createMinimalMemoryBankMd() {
283
+ return `# Memory Bank
284
+
285
+ ## Quick Reference
286
+ - Project uses JSON for memory persistence
287
+ - Memory is organized by namespaces
288
+ - Query with \`npx claude-flow memory query <search>\`
289
+
290
+ ## Storage Location
291
+ - Database: \`./memory/claude-flow-data.json\`
292
+ - Sessions: \`./memory/sessions/\`
293
+ `;
294
+ }
295
+
296
+ function createFullMemoryBankMd() {
297
+ return `# Memory Bank Configuration
298
+
299
+ ## Overview
300
+ The Claude-Flow memory system provides persistent storage and intelligent retrieval of information across agent sessions. It uses a hybrid approach combining JSON databases with semantic search capabilities.
301
+
302
+ ## Storage Backends
303
+ - **Primary**: JSON database (\`./memory/claude-flow-data.json\`)
304
+ - **Sessions**: File-based storage in \`./memory/sessions/\`
305
+ - **Cache**: In-memory cache for frequently accessed data
306
+
307
+ ## Memory Organization
308
+ - **Namespaces**: Logical groupings of related information
309
+ - **Sessions**: Time-bound conversation contexts
310
+ - **Indexing**: Automatic content indexing for fast retrieval
311
+ - **Replication**: Optional distributed storage support
312
+
313
+ ## Commands
314
+ - \`npx claude-flow memory query <search>\`: Search stored information
315
+ - \`npx claude-flow memory stats\`: Show memory usage statistics
316
+ - \`npx claude-flow memory export <file>\`: Export memory to file
317
+ - \`npx claude-flow memory import <file>\`: Import memory from file
318
+
319
+ ## Configuration
320
+ Memory settings are configured in \`claude-flow.config.json\`:
321
+ \`\`\`json
322
+ {
323
+ "memory": {
324
+ "backend": "json",
325
+ "path": "./memory/claude-flow-data.json",
326
+ "cacheSize": 1000,
327
+ "indexing": true,
328
+ "namespaces": ["default", "agents", "tasks", "sessions"],
329
+ "retentionPolicy": {
330
+ "sessions": "30d",
331
+ "tasks": "90d",
332
+ "agents": "permanent"
333
+ }
334
+ }
335
+ }
336
+ \`\`\`
337
+
338
+ ## Best Practices
339
+ - Use descriptive namespaces for different data types
340
+ - Regular memory exports for backup purposes
341
+ - Monitor memory usage with stats command
342
+ - Clean up old sessions periodically
343
+
344
+ ## Memory Types
345
+ - **Episodic**: Conversation and interaction history
346
+ - **Semantic**: Factual knowledge and relationships
347
+ - **Procedural**: Task patterns and workflows
348
+ - **Meta**: System configuration and preferences
349
+
350
+ ## Integration Notes
351
+ - Memory is automatically synchronized across agents
352
+ - Search supports both exact match and semantic similarity
353
+ - Memory contents are private to your local instance
354
+ - No data is sent to external services without explicit commands
355
+ `;
356
+ }
357
+
358
+ function createMinimalCoordinationMd() {
359
+ return `# Agent Coordination
360
+
361
+ ## Quick Commands
362
+ - \`npx claude-flow agent spawn <type>\`: Create new agent
363
+ - \`npx claude-flow agent list\`: Show active agents
364
+ - \`npx claude-flow task create <type> <description>\`: Create task
365
+
366
+ ## Agent Types
367
+ - researcher, coder, analyst, coordinator, general
368
+ `;
369
+ }
370
+
371
+ function createFullCoordinationMd() {
372
+ return `# Agent Coordination System
373
+
374
+ ## Overview
375
+ The Claude-Flow coordination system manages multiple AI agents working together on complex tasks. It provides intelligent task distribution, resource management, and inter-agent communication.
376
+
377
+ ## Agent Types and Capabilities
378
+ - **Researcher**: Web search, information gathering, knowledge synthesis
379
+ - **Coder**: Code analysis, development, debugging, testing
380
+ - **Analyst**: Data processing, pattern recognition, insights generation
381
+ - **Coordinator**: Task planning, resource allocation, workflow management
382
+ - **General**: Multi-purpose agent with balanced capabilities
383
+
384
+ ## Task Management
385
+ - **Priority Levels**: 1 (lowest) to 10 (highest)
386
+ - **Dependencies**: Tasks can depend on completion of other tasks
387
+ - **Parallel Execution**: Independent tasks run concurrently
388
+ - **Load Balancing**: Automatic distribution based on agent capacity
389
+
390
+ ## Coordination Commands
391
+ \`\`\`bash
392
+ # Agent Management
393
+ npx claude-flow agent spawn <type> --name <name> --priority <1-10>
394
+ npx claude-flow agent list
395
+ npx claude-flow agent info <agent-id>
396
+ npx claude-flow agent terminate <agent-id>
397
+
398
+ # Task Management
399
+ npx claude-flow task create <type> <description> --priority <1-10> --deps <task-ids>
400
+ npx claude-flow task list --verbose
401
+ npx claude-flow task status <task-id>
402
+ npx claude-flow task cancel <task-id>
403
+
404
+ # System Monitoring
405
+ npx claude-flow status --verbose
406
+ npx claude-flow monitor --interval 5000
407
+ \`\`\`
408
+
409
+ ## Workflow Execution
410
+ Workflows are defined in JSON format and can orchestrate complex multi-agent operations:
411
+ \`\`\`bash
412
+ npx claude-flow workflow examples/research-workflow.json
413
+ npx claude-flow workflow examples/development-config.json --async
414
+ \`\`\`
415
+
416
+ ## Advanced Features
417
+ - **Circuit Breakers**: Automatic failure handling and recovery
418
+ - **Work Stealing**: Dynamic load redistribution for efficiency
419
+ - **Resource Limits**: Memory and CPU usage constraints
420
+ - **Metrics Collection**: Performance monitoring and optimization
421
+
422
+ ## Configuration
423
+ Coordination settings in \`claude-flow.config.json\`:
424
+ \`\`\`json
425
+ {
426
+ "orchestrator": {
427
+ "maxConcurrentTasks": 10,
428
+ "taskTimeout": 300000,
429
+ "defaultPriority": 5
430
+ },
431
+ "agents": {
432
+ "maxAgents": 20,
433
+ "defaultCapabilities": ["research", "code", "terminal"],
434
+ "resourceLimits": {
435
+ "memory": "1GB",
436
+ "cpu": "50%"
437
+ }
438
+ }
439
+ }
440
+ \`\`\`
441
+
442
+ ## Communication Patterns
443
+ - **Direct Messaging**: Agent-to-agent communication
444
+ - **Event Broadcasting**: System-wide notifications
445
+ - **Shared Memory**: Common information access
446
+ - **Task Handoff**: Seamless work transfer between agents
447
+
448
+ ## Best Practices
449
+ - Start with general agents and specialize as needed
450
+ - Use descriptive task names and clear requirements
451
+ - Monitor system resources during heavy workloads
452
+ - Implement proper error handling in workflows
453
+ - Regular cleanup of completed tasks and inactive agents
454
+
455
+ ## Troubleshooting
456
+ - Check agent health with \`npx claude-flow status\`
457
+ - View detailed logs with \`npx claude-flow monitor\`
458
+ - Restart stuck agents with terminate/spawn cycle
459
+ - Use \`--verbose\` flags for detailed diagnostic information
460
+ `;
461
+ }
462
+
463
+ function createAgentsReadme() {
464
+ return `# Agent Memory Storage
465
+
466
+ ## Purpose
467
+ This directory stores agent-specific memory data, configurations, and persistent state information for individual Claude agents in the orchestration system.
468
+
469
+ ## Structure
470
+ Each agent gets its own subdirectory for isolated memory storage:
471
+
472
+ \`\`\`
473
+ memory/agents/
474
+ ├── agent_001/
475
+ │ ├── state.json # Agent state and configuration
476
+ │ ├── knowledge.md # Agent-specific knowledge base
477
+ │ ├── tasks.json # Completed and active tasks
478
+ │ └── calibration.json # Agent-specific calibrations
479
+ ├── agent_002/
480
+ │ └── ...
481
+ └── shared/
482
+ ├── common_knowledge.md # Shared knowledge across agents
483
+ └── global_config.json # Global agent configurations
484
+ \`\`\`
485
+
486
+ ## Usage Guidelines
487
+ 1. **Agent Isolation**: Each agent should only read/write to its own directory
488
+ 2. **Shared Resources**: Use the \`shared/\` directory for cross-agent information
489
+ 3. **State Persistence**: Update state.json whenever agent status changes
490
+ 4. **Knowledge Sharing**: Document discoveries in knowledge.md files
491
+ 5. **Cleanup**: Remove directories for terminated agents periodically
492
+
493
+ ## Last Updated
494
+ ${new Date().toISOString()}
495
+ `;
496
+ }
497
+
498
+ function createSessionsReadme() {
499
+ return `# Session Memory Storage
500
+
501
+ ## Purpose
502
+ This directory stores session-based memory data, conversation history, and contextual information for development sessions using the Claude-Flow orchestration system.
503
+
504
+ ## Structure
505
+ Sessions are organized by date and session ID for easy retrieval:
506
+
507
+ \`\`\`
508
+ memory/sessions/
509
+ ├── 2024-01-10/
510
+ │ ├── session_001/
511
+ │ │ ├── metadata.json # Session metadata and configuration
512
+ │ │ ├── conversation.md # Full conversation history
513
+ │ │ ├── decisions.md # Key decisions and rationale
514
+ │ │ ├── artifacts/ # Generated files and outputs
515
+ │ │ └── coordination_state/ # Coordination system snapshots
516
+ │ └── ...
517
+ └── shared/
518
+ ├── patterns.md # Common session patterns
519
+ └── templates/ # Session template files
520
+ \`\`\`
521
+
522
+ ## Usage Guidelines
523
+ 1. **Session Isolation**: Each session gets its own directory
524
+ 2. **Metadata Completeness**: Always fill out session metadata
525
+ 3. **Conversation Logging**: Document all significant interactions
526
+ 4. **Artifact Organization**: Structure generated files clearly
527
+ 5. **State Preservation**: Snapshot coordination state regularly
528
+
529
+ ## Last Updated
530
+ ${new Date().toISOString()}
531
+ `;
532
+ }
533
+
534
+ // Main CLI handler
535
+ async function main() {
536
+ const args = process.argv.slice(2);
537
+ const command = args[0];
538
+
539
+ if (!command || command === 'help' || command === '--help') {
540
+ printHelp();
541
+ return;
542
+ }
543
+
544
+ if (command === 'version' || command === '--version') {
545
+ console.log(`Claude-Flow v${VERSION}`);
546
+ return;
547
+ }
548
+
549
+ switch (command) {
550
+ case 'init':
551
+ await executeInit(args.slice(1));
552
+ break;
553
+
554
+ case 'status':
555
+ await executeStatus();
556
+ break;
557
+
558
+ case 'start':
559
+ warning('Starting the orchestrator requires the full Deno-based implementation.');
560
+ console.log('Please install Deno from https://deno.land/ and run:');
561
+ console.log(' deno run --allow-all src/cli/index.ts start');
562
+ break;
563
+
564
+ case 'agent':
565
+ case 'task':
566
+ case 'memory':
567
+ case 'config':
568
+ case 'monitor':
569
+ case 'mcp':
570
+ case 'claude':
571
+ case 'session':
572
+ case 'workflow':
573
+ warning(`The '${command}' command requires the full Deno-based implementation.`);
574
+ console.log('Please install Deno from https://deno.land/ and run:');
575
+ console.log(` deno run --allow-all src/cli/index.ts ${command} ${args.slice(1).join(' ')}`);
576
+ break;
577
+
578
+ default:
579
+ error(`Unknown command: ${command}`);
580
+ console.log('Run \'claude-flow help\' for usage information.');
581
+ process.exit(1);
582
+ }
583
+ }
584
+
585
+ // Run the CLI
586
+ main().catch(err => {
587
+ error(`Fatal error: ${err.message}`);
588
+ process.exit(1);
589
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Advanced AI agent orchestration system for Claude Code",
5
5
  "main": "src/cli/main.ts",
6
6
  "bin": {
@@ -35,7 +35,7 @@
35
35
  "node": ">=16.0.0"
36
36
  },
37
37
  "files": [
38
- "bin/claude-flow",
38
+ "bin/",
39
39
  "src/",
40
40
  "scripts/install.js",
41
41
  "README.md",