enhance_swarm 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 (64) hide show
  1. checksums.yaml +7 -0
  2. data/.enhance_swarm/agent_scripts/frontend_agent.md +39 -0
  3. data/.enhance_swarm/user_patterns.json +37 -0
  4. data/CHANGELOG.md +184 -0
  5. data/LICENSE +21 -0
  6. data/PRODUCTION_TEST_LOG.md +502 -0
  7. data/README.md +905 -0
  8. data/Rakefile +28 -0
  9. data/USAGE_EXAMPLES.md +477 -0
  10. data/examples/enhance_workflow.md +346 -0
  11. data/examples/rails_project.md +253 -0
  12. data/exe/enhance-swarm +30 -0
  13. data/lib/enhance_swarm/additional_commands.rb +299 -0
  14. data/lib/enhance_swarm/agent_communicator.rb +460 -0
  15. data/lib/enhance_swarm/agent_reviewer.rb +283 -0
  16. data/lib/enhance_swarm/agent_spawner.rb +462 -0
  17. data/lib/enhance_swarm/cleanup_manager.rb +245 -0
  18. data/lib/enhance_swarm/cli.rb +1592 -0
  19. data/lib/enhance_swarm/command_executor.rb +78 -0
  20. data/lib/enhance_swarm/configuration.rb +324 -0
  21. data/lib/enhance_swarm/control_agent.rb +307 -0
  22. data/lib/enhance_swarm/dependency_validator.rb +195 -0
  23. data/lib/enhance_swarm/error_recovery.rb +785 -0
  24. data/lib/enhance_swarm/generator.rb +194 -0
  25. data/lib/enhance_swarm/interrupt_handler.rb +512 -0
  26. data/lib/enhance_swarm/logger.rb +106 -0
  27. data/lib/enhance_swarm/mcp_integration.rb +85 -0
  28. data/lib/enhance_swarm/monitor.rb +28 -0
  29. data/lib/enhance_swarm/notification_manager.rb +444 -0
  30. data/lib/enhance_swarm/orchestrator.rb +313 -0
  31. data/lib/enhance_swarm/output_streamer.rb +281 -0
  32. data/lib/enhance_swarm/process_monitor.rb +266 -0
  33. data/lib/enhance_swarm/progress_tracker.rb +215 -0
  34. data/lib/enhance_swarm/project_analyzer.rb +612 -0
  35. data/lib/enhance_swarm/resource_manager.rb +177 -0
  36. data/lib/enhance_swarm/retry_handler.rb +40 -0
  37. data/lib/enhance_swarm/session_manager.rb +247 -0
  38. data/lib/enhance_swarm/signal_handler.rb +95 -0
  39. data/lib/enhance_swarm/smart_defaults.rb +708 -0
  40. data/lib/enhance_swarm/task_integration.rb +150 -0
  41. data/lib/enhance_swarm/task_manager.rb +174 -0
  42. data/lib/enhance_swarm/version.rb +5 -0
  43. data/lib/enhance_swarm/visual_dashboard.rb +555 -0
  44. data/lib/enhance_swarm/web_ui.rb +211 -0
  45. data/lib/enhance_swarm.rb +69 -0
  46. data/setup.sh +86 -0
  47. data/sig/enhance_swarm.rbs +4 -0
  48. data/templates/claude/CLAUDE.md +160 -0
  49. data/templates/claude/MCP.md +117 -0
  50. data/templates/claude/PERSONAS.md +114 -0
  51. data/templates/claude/RULES.md +221 -0
  52. data/test_builtin_functionality.rb +121 -0
  53. data/test_core_components.rb +156 -0
  54. data/test_real_claude_integration.rb +285 -0
  55. data/test_security.rb +150 -0
  56. data/test_smart_defaults.rb +155 -0
  57. data/test_task_integration.rb +173 -0
  58. data/test_web_ui.rb +245 -0
  59. data/web/assets/css/main.css +645 -0
  60. data/web/assets/js/kanban.js +499 -0
  61. data/web/assets/js/main.js +525 -0
  62. data/web/templates/dashboard.html.erb +226 -0
  63. data/web/templates/kanban.html.erb +193 -0
  64. metadata +293 -0
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
11
+
12
+ desc 'Install the gem locally'
13
+ task :install_local do
14
+ sh 'bundle exec rake build'
15
+ sh 'gem install pkg/enhance_swarm-*.gem'
16
+ end
17
+
18
+ desc 'Run a quick test of the CLI'
19
+ task :test_cli do
20
+ sh 'bundle exec exe/enhance-swarm --help'
21
+ sh 'bundle exec exe/enhance-swarm version'
22
+ sh 'bundle exec exe/enhance-swarm doctor'
23
+ end
24
+
25
+ desc 'Generate documentation'
26
+ task :docs do
27
+ sh 'yard doc'
28
+ end
data/USAGE_EXAMPLES.md ADDED
@@ -0,0 +1,477 @@
1
+ # EnhanceSwarm UX Features - Usage Examples
2
+
3
+ This document shows how to use the 6 major UX improvements in EnhanceSwarm, both via CLI commands and programmatically.
4
+
5
+ ## ✅ Confirmed Working Features
6
+
7
+ ### 🎯 UX #1: Live Agent Output Streaming
8
+
9
+ **CLI Usage:**
10
+ ```bash
11
+ # Stream live output during orchestration
12
+ enhance-swarm enhance "implement user auth" --follow
13
+
14
+ # Stream output from single agent
15
+ enhance-swarm spawn "fix login bug" --role backend --follow
16
+ ```
17
+
18
+ **Programmatic Usage:**
19
+ ```ruby
20
+ # Create output streamer
21
+ streamer = EnhanceSwarm::OutputStreamer.new(agent_id: 'backend-123')
22
+
23
+ # Stream with progress tracking
24
+ streamer.stream_with_progress do |progress|
25
+ puts "Progress: #{progress[:percentage]}% - #{progress[:current_task]}"
26
+ end
27
+
28
+ # Custom streaming with callbacks
29
+ streamer.start_streaming(
30
+ on_output: ->(line) { puts "[AGENT] #{line}" },
31
+ on_progress: ->(pct) { puts "Progress: #{pct}%" },
32
+ on_complete: -> { puts "Agent completed!" }
33
+ )
34
+ ```
35
+
36
+ ### 🔔 UX #2: Smart Notifications & Interrupts
37
+
38
+ **CLI Usage:**
39
+ ```bash
40
+ # Test notification system
41
+ enhance-swarm notifications --test
42
+
43
+ # Enable/disable notifications
44
+ enhance-swarm notifications --enable
45
+ enhance-swarm notifications --disable
46
+
47
+ # Show notification status
48
+ enhance-swarm notifications
49
+ ```
50
+
51
+ **Programmatic Usage:**
52
+ ```ruby
53
+ # Get notification manager
54
+ nm = EnhanceSwarm::NotificationManager.instance
55
+
56
+ # Send different types of notifications
57
+ nm.agent_completed('backend-123', 'backend', 300)
58
+ nm.agent_failed('frontend-456', 'Connection timeout', { retry_count: 3 })
59
+ nm.progress_milestone('system', 'Backend tests passing', 75)
60
+
61
+ # Configure notification preferences
62
+ nm.configure(
63
+ desktop_notifications: true,
64
+ sound_alerts: true,
65
+ priority_filter: :medium # :low, :medium, :high, :critical
66
+ )
67
+
68
+ # Set up interrupt handling
69
+ interrupt_handler = EnhanceSwarm::InterruptHandler.new(nm)
70
+ interrupt_handler.enable_interrupts!
71
+
72
+ # Handle stuck agents
73
+ result = interrupt_handler.handle_agent_stuck(agent)
74
+ # => { action: :restart, success: true }
75
+ ```
76
+
77
+ ### 💬 UX #3: Quick Agent Communication
78
+
79
+ **CLI Usage:**
80
+ ```bash
81
+ # Demo agent communication
82
+ enhance-swarm communicate --demo
83
+
84
+ # Show communication status
85
+ enhance-swarm communicate --status
86
+ enhance-swarm communicate
87
+ ```
88
+
89
+ **Programmatic Usage:**
90
+ ```ruby
91
+ # Get communicator
92
+ comm = EnhanceSwarm::AgentCommunicator.instance
93
+
94
+ # Agent asks questions with quick actions
95
+ comm.agent_question(
96
+ 'backend-auth',
97
+ 'Should I use Devise or build custom auth?',
98
+ ['Devise', 'Custom', 'Research both'],
99
+ priority: :high,
100
+ timeout: 300
101
+ )
102
+
103
+ # Agent sends status updates
104
+ comm.agent_status('frontend-ui', 'Components 80% complete')
105
+
106
+ # Agent reports progress
107
+ comm.agent_progress('qa-tests', 'Running integration tests...', 65)
108
+
109
+ # Agent requests decisions
110
+ comm.agent_decision(
111
+ 'backend-db',
112
+ 'Database schema migration needed. Proceed?',
113
+ ['Yes', 'No', 'Review first']
114
+ )
115
+
116
+ # Check for pending messages
117
+ pending = comm.pending_messages
118
+ recent = comm.recent_messages(10)
119
+
120
+ # Respond to messages
121
+ comm.respond_to_message('msg_123', 'Use Devise for faster development')
122
+ ```
123
+
124
+ ### 🖥️ UX #4: Visual Agent Dashboard
125
+
126
+ **CLI Usage:**
127
+ ```bash
128
+ # Start dashboard with running agents
129
+ enhance-swarm dashboard
130
+
131
+ # Take a snapshot
132
+ enhance-swarm dashboard --snapshot
133
+
134
+ # Monitor specific agents
135
+ enhance-swarm dashboard --agents backend-123 frontend-456
136
+
137
+ # Custom refresh rate
138
+ enhance-swarm dashboard --refresh 1
139
+ ```
140
+
141
+ **Programmatic Usage:**
142
+ ```ruby
143
+ # Get dashboard instance
144
+ dashboard = EnhanceSwarm::VisualDashboard.instance
145
+
146
+ # Start dashboard with agents
147
+ agents = [
148
+ { id: 'backend-123', role: 'backend', status: 'running', progress: 75 },
149
+ { id: 'frontend-456', role: 'frontend', status: 'completed', progress: 100 }
150
+ ]
151
+
152
+ dashboard.start_dashboard(agents)
153
+
154
+ # Display snapshot
155
+ dashboard.display_snapshot(agents)
156
+
157
+ # Configure dashboard
158
+ dashboard.configure(
159
+ refresh_rate: 2,
160
+ show_system_resources: true,
161
+ color_scheme: :dark
162
+ )
163
+
164
+ # Get dashboard status
165
+ status = dashboard.get_status
166
+ # => {
167
+ # active_agents: 2,
168
+ # total_memory: "8.2GB",
169
+ # system_load: 0.45
170
+ # }
171
+ ```
172
+
173
+ ### 🧠 UX #5: Smart Defaults & Auto-Actions
174
+
175
+ **CLI Usage:**
176
+ ```bash
177
+ # Get smart suggestions
178
+ enhance-swarm suggest
179
+
180
+ # Get suggestions with context
181
+ enhance-swarm suggest --context "need better performance"
182
+ ```
183
+
184
+ **Programmatic Usage:**
185
+ ```ruby
186
+ # Get smart defaults instance
187
+ sd = EnhanceSwarm::SmartDefaults.instance
188
+
189
+ # Get suggestions for current context
190
+ context = {
191
+ git_status: { modified_files: 5, untracked_files: 2 },
192
+ project_files: { ruby_files: 20, test_files: 15 },
193
+ recent_actions: ['enhance', 'spawn backend']
194
+ }
195
+
196
+ suggestions = sd.get_suggestions(context)
197
+ # => [
198
+ # { priority: :high, description: "Run tests before commit", command: "rspec" },
199
+ # { priority: :medium, description: "Clean up stale worktrees", command: "enhance-swarm cleanup --all" }
200
+ # ]
201
+
202
+ # Auto-detect role for task
203
+ role = sd.suggest_role_for_task("implement payment API endpoints")
204
+ # => "backend"
205
+
206
+ # Generate smart configuration
207
+ config = sd.generate_smart_config
208
+ sd.apply_config(config)
209
+
210
+ # Learn from user actions
211
+ sd.learn_from_action('enhance', {
212
+ task: 'implement auth',
213
+ role_used: 'backend',
214
+ success: true
215
+ })
216
+
217
+ # Auto-cleanup with intelligence
218
+ cleanup_count = sd.auto_cleanup_if_needed
219
+ # => 3 (number of resources cleaned)
220
+ ```
221
+
222
+ ### 🔧 UX #6: Better Error Recovery
223
+
224
+ **CLI Usage:**
225
+ ```bash
226
+ # Analyze specific error
227
+ enhance-swarm recover --analyze "Connection timeout after 30 seconds"
228
+
229
+ # Show recovery statistics
230
+ enhance-swarm recover --stats
231
+
232
+ # Demo error recovery features
233
+ enhance-swarm recover --demo
234
+ ```
235
+
236
+ **Programmatic Usage:**
237
+ ```ruby
238
+ # Get error recovery instance
239
+ er = EnhanceSwarm::ErrorRecovery.instance
240
+
241
+ # Analyze an error
242
+ begin
243
+ # Some operation that might fail
244
+ result = risky_operation()
245
+ rescue StandardError => e
246
+ analysis = er.analyze_error(e, { agent_id: 'backend-123', context: 'database_operation' })
247
+
248
+ # => {
249
+ # error: { type: 'StandardError', message: '...', timestamp: '...' },
250
+ # patterns: [...],
251
+ # suggestions: [
252
+ # { description: 'Retry with exponential backoff', auto_executable: true },
253
+ # { description: 'Check network connectivity', auto_executable: false }
254
+ # ],
255
+ # auto_recoverable: true
256
+ # }
257
+
258
+ # Attempt automatic recovery
259
+ if analysis[:auto_recoverable]
260
+ recovery_result = er.attempt_recovery(analysis, {
261
+ retry_block: -> { risky_operation() },
262
+ timeout: 60
263
+ })
264
+
265
+ if recovery_result[:success]
266
+ puts "✅ Automatically recovered!"
267
+ else
268
+ puts "❌ Recovery failed, manual intervention needed"
269
+ end
270
+ end
271
+ end
272
+
273
+ # Get human-readable error explanation
274
+ explanation = er.explain_error(error, context: { operation: 'database_query' })
275
+ # => {
276
+ # explanation: "Connection timeout typically occurs when...",
277
+ # likely_cause: "Network latency or server overload",
278
+ # prevention_tips: ["Implement retry logic", "Monitor connectivity", ...]
279
+ # }
280
+
281
+ # Learn from manual recovery
282
+ er.learn_from_manual_recovery(
283
+ error,
284
+ ['restart database service', 'clear connection pool', 'retry operation'],
285
+ { success: true, time_taken: 45 }
286
+ )
287
+
288
+ # Get recovery statistics
289
+ stats = er.recovery_statistics
290
+ # => {
291
+ # total_errors_processed: 25,
292
+ # successful_automatic_recoveries: 18,
293
+ # recovery_success_rate: 72.0,
294
+ # most_common_errors: { "ConnectionError" => 8, "TimeoutError" => 5 }
295
+ # }
296
+
297
+ # Clean up old data
298
+ er.cleanup_old_data(30) # Keep last 30 days
299
+ ```
300
+
301
+ ## 🎛️ Integrated Workflows
302
+
303
+ ### Complete Development Workflow
304
+
305
+ ```ruby
306
+ # 1. Enable notifications and smart features
307
+ nm = EnhanceSwarm::NotificationManager.instance
308
+ nm.enable!
309
+
310
+ sd = EnhanceSwarm::SmartDefaults.instance
311
+ sd.auto_cleanup_if_needed
312
+
313
+ # 2. Start with smart suggestions
314
+ suggestions = sd.get_suggestions({})
315
+ high_priority = suggestions.select { |s| s[:priority] == :high }
316
+
317
+ # 3. Execute enhancement with full monitoring
318
+ orchestrator = EnhanceSwarm::Orchestrator.new
319
+ orchestrator.enhance(
320
+ task: "implement user dashboard",
321
+ follow: true,
322
+ notifications: true
323
+ )
324
+
325
+ # 4. Monitor via dashboard
326
+ dashboard = EnhanceSwarm::VisualDashboard.instance
327
+ dashboard.start_dashboard(orchestrator.active_agents)
328
+
329
+ # 5. Handle any errors automatically
330
+ EnhanceSwarm::ErrorRecovery.instance.enable_auto_recovery!
331
+ ```
332
+
333
+ ### Agent Communication Workflow
334
+
335
+ ```ruby
336
+ comm = EnhanceSwarm::AgentCommunicator.instance
337
+
338
+ # Agent asks for user input
339
+ response = comm.agent_question(
340
+ 'backend-db',
341
+ 'Database migration will modify user table. Proceed?',
342
+ ['Yes', 'No', 'Review SQL first'],
343
+ timeout: 300
344
+ )
345
+
346
+ # User responds
347
+ comm.respond_to_message(response[:message_id], 'Review SQL first')
348
+
349
+ # Agent provides more details
350
+ comm.agent_status('backend-db', 'Generating migration preview...')
351
+
352
+ # Continue workflow based on response
353
+ case response[:text]
354
+ when 'Yes'
355
+ comm.agent_status('backend-db', 'Running migration...')
356
+ when 'Review SQL first'
357
+ comm.agent_question('backend-db', 'Migration SQL: ALTER TABLE users ADD COLUMN role VARCHAR(50); Proceed?', ['Yes', 'No'])
358
+ end
359
+ ```
360
+
361
+ ## 🚀 Integration with Existing Tools
362
+
363
+ ### Rails Integration
364
+
365
+ ```ruby
366
+ # In your Rails app
367
+ class ApplicationController < ActionController::Base
368
+ before_action :setup_enhance_swarm
369
+
370
+ private
371
+
372
+ def setup_enhance_swarm
373
+ if Rails.env.development?
374
+ @enhancer = EnhanceSwarm::SmartDefaults.instance
375
+ @notifier = EnhanceSwarm::NotificationManager.instance
376
+ @notifier.enable! if params[:enhance_notifications]
377
+ end
378
+ end
379
+ end
380
+
381
+ # In rake tasks
382
+ task enhance_and_test: :environment do
383
+ orchestrator = EnhanceSwarm::Orchestrator.new
384
+
385
+ # Run enhancement with error recovery
386
+ begin
387
+ result = orchestrator.enhance(task: "optimize database queries")
388
+
389
+ if result[:success]
390
+ # Run tests to verify
391
+ system('bundle exec rspec')
392
+ end
393
+ rescue => e
394
+ recovery = EnhanceSwarm::ErrorRecovery.instance
395
+ recovery.analyze_error(e, context: { task: 'optimization', environment: 'test' })
396
+ end
397
+ end
398
+ ```
399
+
400
+ ### CI/CD Integration
401
+
402
+ ```yaml
403
+ # .github/workflows/enhance-swarm.yml
404
+ name: EnhanceSwarm Integration
405
+ on: [push]
406
+
407
+ jobs:
408
+ enhance:
409
+ runs-on: ubuntu-latest
410
+ steps:
411
+ - uses: actions/checkout@v2
412
+ - name: Setup Ruby
413
+ uses: ruby/setup-ruby@v1
414
+ with:
415
+ ruby-version: 3.3.0
416
+ - name: Install EnhanceSwarm
417
+ run: |
418
+ bundle add enhance_swarm
419
+ bundle exec enhance-swarm init
420
+ - name: Run Enhancement
421
+ run: |
422
+ bundle exec enhance-swarm enhance "optimize performance" --notifications=false
423
+ - name: Verify Results
424
+ run: |
425
+ bundle exec enhance-swarm troubleshoot
426
+ bundle exec rspec
427
+ ```
428
+
429
+ ## 📊 Monitoring and Analytics
430
+
431
+ ```ruby
432
+ # Custom monitoring setup
433
+ class EnhanceSwarmMonitor
434
+ def initialize
435
+ @dashboard = EnhanceSwarm::VisualDashboard.instance
436
+ @notifications = EnhanceSwarm::NotificationManager.instance
437
+ @recovery = EnhanceSwarm::ErrorRecovery.instance
438
+ end
439
+
440
+ def daily_report
441
+ stats = @recovery.recovery_statistics
442
+
443
+ report = {
444
+ date: Date.current,
445
+ enhancements_run: count_enhancements_today,
446
+ success_rate: stats[:recovery_success_rate],
447
+ common_errors: stats[:most_common_errors],
448
+ agent_usage: @dashboard.get_usage_stats
449
+ }
450
+
451
+ # Send notification with daily summary
452
+ @notifications.daily_summary(report)
453
+
454
+ report
455
+ end
456
+
457
+ def health_check
458
+ {
459
+ notifications: @notifications.enabled?,
460
+ dashboard: @dashboard.available?,
461
+ error_recovery: @recovery.recovery_statistics[:total_errors_processed],
462
+ last_enhancement: File.mtime('.enhance_swarm.yml') rescue nil
463
+ }
464
+ end
465
+ end
466
+ ```
467
+
468
+ ## 🎯 Best Practices
469
+
470
+ 1. **Always enable notifications for long-running enhancements**
471
+ 2. **Use the dashboard to monitor multiple agents**
472
+ 3. **Let error recovery handle transient failures automatically**
473
+ 4. **Use smart suggestions to optimize your workflow**
474
+ 5. **Set up agent communication for complex decisions**
475
+ 6. **Run troubleshooting when issues arise**
476
+
477
+ For more examples and advanced usage, see the main README.md file.