Class: EnhanceSwarm::NotificationManager
- Inherits:
-
Object
- Object
- EnhanceSwarm::NotificationManager
- Defined in:
- lib/enhance_swarm/notification_manager.rb
Constant Summary collapse
- NOTIFICATION_TYPES =
{ agent_completed: { priority: :high, desktop: true, sound: true }, agent_failed: { priority: :critical, desktop: true, sound: true }, agent_stuck: { priority: :high, desktop: true, sound: false }, coordination_complete: { priority: :medium, desktop: true, sound: true }, intervention_needed: { priority: :critical, desktop: true, sound: true }, progress_milestone: { priority: :low, desktop: false, sound: false } }.freeze
Instance Method Summary collapse
- #agent_completed(agent_id, role, duration, details = {}) ⇒ Object
- #agent_failed(agent_id, role, error, suggestions = []) ⇒ Object
- #agent_stuck(agent_id, role, last_activity, current_task = nil) ⇒ Object
- #clear_history ⇒ Object
- #coordination_complete(summary) ⇒ Object
- #disable! ⇒ Object
-
#enable! ⇒ Object
Enable/disable notifications.
- #enabled? ⇒ Boolean
-
#initialize ⇒ NotificationManager
constructor
A new instance of NotificationManager.
- #intervention_needed(reason, agent_id = nil, suggestions = []) ⇒ Object
- #notify(type, message, details = {}) ⇒ Object
- #progress_milestone(milestone, progress_percentage, eta = nil) ⇒ Object
-
#recent_notifications(limit = 10) ⇒ Object
Notification history.
-
#start_monitoring(agents) ⇒ Object
Background monitoring for stuck agents.
- #stop_monitoring ⇒ Object
-
#test_notifications ⇒ Object
Test notification system.
Constructor Details
#initialize ⇒ NotificationManager
Returns a new instance of NotificationManager.
16 17 18 19 20 21 |
# File 'lib/enhance_swarm/notification_manager.rb', line 16 def initialize @enabled = true @desktop_notifications = desktop_notifications_available? @sound_enabled = sound_available? @notification_history = [] end |
Instance Method Details
#agent_completed(agent_id, role, duration, details = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/enhance_swarm/notification_manager.rb', line 52 def agent_completed(agent_id, role, duration, details = {}) = "๐ Agent '#{role}' completed successfully!" notify(:agent_completed, , { agent_id: agent_id, role: role, duration: duration, **details }) if details[:output_path] puts " View: enhance-swarm show #{agent_id}".colorize(:blue) end end |
#agent_failed(agent_id, role, error, suggestions = []) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/enhance_swarm/notification_manager.rb', line 67 def agent_failed(agent_id, role, error, suggestions = []) = "โ Agent '#{role}' failed: #{error}" notify(:agent_failed, , { agent_id: agent_id, role: role, error: error, suggestions: suggestions }) if suggestions.any? puts "\n๐ก Quick fixes:".colorize(:yellow) suggestions.each_with_index do |suggestion, index| puts " #{index + 1}. #{suggestion}".colorize(:yellow) end puts "\nChoose [1-#{suggestions.length}] or [c]ustom command:".colorize(:yellow) end end |
#agent_stuck(agent_id, role, last_activity, current_task = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/enhance_swarm/notification_manager.rb', line 86 def agent_stuck(agent_id, role, last_activity, current_task = nil) time_stuck = Time.now - last_activity time_str = format_duration(time_stuck) = "โ ๏ธ Agent '#{role}' stuck for #{time_str}" notify(:agent_stuck, , { agent_id: agent_id, role: role, last_activity: last_activity, time_stuck: time_stuck, current_task: current_task }) puts " Last activity: #{current_task || 'Unknown'}".colorize(:yellow) puts " Action: enhance-swarm restart #{agent_id} [y/N]?".colorize(:blue) end |
#clear_history ⇒ Object
180 181 182 |
# File 'lib/enhance_swarm/notification_manager.rb', line 180 def clear_history @notification_history.clear end |
#coordination_complete(summary) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/enhance_swarm/notification_manager.rb', line 104 def coordination_complete(summary) total_agents = summary[:completed] + summary[:failed] = "โ Coordination complete: #{summary[:completed]}/#{total_agents} agents succeeded" notify(:coordination_complete, , summary) if summary[:failed] > 0 puts "\nโ ๏ธ #{summary[:failed]} agent(s) failed. Review with: enhance-swarm review".colorize(:yellow) end end |
#disable! ⇒ Object
166 167 168 169 |
# File 'lib/enhance_swarm/notification_manager.rb', line 166 def disable! @enabled = false puts "๐ Notifications disabled".colorize(:yellow) end |
#enable! ⇒ Object
Enable/disable notifications
161 162 163 164 |
# File 'lib/enhance_swarm/notification_manager.rb', line 161 def enable! @enabled = true puts "โ Notifications enabled".colorize(:green) end |
#enabled? ⇒ Boolean
171 172 173 |
# File 'lib/enhance_swarm/notification_manager.rb', line 171 def enabled? @enabled end |
#intervention_needed(reason, agent_id = nil, suggestions = []) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/enhance_swarm/notification_manager.rb', line 115 def intervention_needed(reason, agent_id = nil, suggestions = []) = "๐จ Intervention needed: #{reason}" notify(:intervention_needed, , { reason: reason, agent_id: agent_id, suggestions: suggestions }) if suggestions.any? puts "\nRecommended actions:".colorize(:red) suggestions.each_with_index do |suggestion, index| puts " #{index + 1}. #{suggestion}".colorize(:red) end end end |
#notify(type, message, details = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/enhance_swarm/notification_manager.rb', line 23 def notify(type, , details = {}) return unless @enabled notification = build_notification(type, , details) @notification_history << notification # Console notification (always shown) display_console_notification(notification) # Desktop notification (if available and configured) if should_show_desktop?(notification) send_desktop_notification(notification) end # Sound notification (if available and configured) if should_play_sound?(notification) play_notification_sound(notification[:priority]) end # Log for automation tools Logger.log_operation("notification_#{type}", 'sent', { message: , priority: notification[:priority], details: details }) notification end |
#progress_milestone(milestone, progress_percentage, eta = nil) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/enhance_swarm/notification_manager.rb', line 132 def progress_milestone(milestone, progress_percentage, eta = nil) = "๐ #{milestone} (#{progress_percentage}% complete)" notify(:progress_milestone, , { milestone: milestone, progress: progress_percentage, eta: eta }) if eta puts " ETA: #{eta.strftime('%H:%M:%S')}".colorize(:blue) end end |
#recent_notifications(limit = 10) ⇒ Object
Notification history
176 177 178 |
# File 'lib/enhance_swarm/notification_manager.rb', line 176 def recent_notifications(limit = 10) @notification_history.last(limit) end |
#start_monitoring(agents) ⇒ Object
Background monitoring for stuck agents
147 148 149 150 151 152 153 |
# File 'lib/enhance_swarm/notification_manager.rb', line 147 def start_monitoring(agents) return if @monitoring_thread&.alive? @monitoring_thread = Thread.new do monitor_agents(agents) end end |
#stop_monitoring ⇒ Object
155 156 157 158 |
# File 'lib/enhance_swarm/notification_manager.rb', line 155 def stop_monitoring @monitoring_thread&.kill @monitoring_thread = nil end |
#test_notifications ⇒ Object
Test notification system
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/enhance_swarm/notification_manager.rb', line 185 def test_notifications puts "๐ Testing notification capabilities...".colorize(:blue) # Test console notification puts "1. Console notifications: โ Available" # Test desktop notifications desktop_available = desktop_notifications_available? puts "2. Desktop notifications: #{desktop_available ? 'โ Available' : 'โ Not available'}" # Test sound notifications sound_available = sound_available? puts "3. Sound notifications: #{sound_available ? 'โ Available' : 'โ Not available'}" puts "\n๐งช Running test notifications..." sleep(1) # Test different notification types agent_completed('test-123', 'backend', 120, { success: true }) sleep(1) progress_milestone('Test milestone reached', 75) sleep(1) puts "\n๐ Test Results:" puts " Notifications sent: 2" puts " History entries: #{@notification_history.count}" puts " Status: #{@enabled ? 'Enabled' : 'Disabled'}" if desktop_available || sound_available puts "\nNote: Desktop/sound notifications may appear with a delay" end puts "\nโ Notification test completed!" end |