5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
# File 'lib/enhance_swarm/additional_commands.rb', line 5
def self.add_commands_to(cli_class)
cli_class.class_eval do
desc 'dashboard', 'Start visual agent dashboard'
option :agents, type: :array, desc: 'Specific agent IDs to monitor'
option :refresh, type: :numeric, default: 2, desc: 'Refresh rate in seconds'
option :snapshot, type: :boolean, desc: 'Take dashboard snapshot and exit'
def dashboard
if options[:snapshot]
agents = discover_running_agents
VisualDashboard.instance.display_snapshot(agents)
return
end
say "๐ฅ๏ธ Starting Visual Agent Dashboard...", :green
agents = options[:agents] ?
load_specific_agents(options[:agents]) :
discover_running_agents
if agents.empty?
say "No agents found, creating demo agents for dashboard...", :yellow
agents = create_demo_agents
end
dashboard = VisualDashboard.instance
dashboard.instance_variable_set(:@refresh_rate, options[:refresh])
begin
dashboard.start_dashboard(agents)
rescue Interrupt
say "\n๐ฅ๏ธ Dashboard stopped by user", :yellow
end
end
desc 'notifications', 'Manage notification settings'
option :enable, type: :boolean, desc: 'Enable notifications'
option :disable, type: :boolean, desc: 'Disable notifications'
option :test, type: :boolean, desc: 'Test notification system'
option :status, type: :boolean, desc: 'Show notification status'
def notifications
notification_manager = NotificationManager.instance
if options[:enable]
notification_manager.enable!
say "โ
Notifications enabled", :green
elsif options[:disable]
notification_manager.disable!
say "๐ Notifications disabled", :yellow
elsif options[:test]
say "๐ Testing notification system...", :blue
notification_manager.test_notifications
say "โ
Notification test completed", :green
else
enabled = notification_manager.enabled?
say "\n๐ฌ Notification Status:", :blue
say " Enabled: #{enabled ? 'โ
Yes' : 'โ No'}"
say " Platform: #{RUBY_PLATFORM}"
if enabled
say "\n๐ Testing notifications..."
notification_manager.agent_completed('demo-123', 'backend', 120, { success: true })
end
end
end
desc 'communicate', 'Manage agent communication and messages'
option :status, type: :boolean, desc: 'Show communication status'
option :demo, type: :boolean, desc: 'Demo communication features'
def communicate
communicator = AgentCommunicator.instance
if options[:demo]
say "๐ฌ Demo Agent Communication", :green
say "Creating demo messages...", :blue
communicator.agent_question('demo-backend', 'Should I use PostgreSQL or MySQL?',
['PostgreSQL', 'MySQL', 'SQLite'])
communicator.agent_status('demo-frontend', 'UI components 60% complete')
say "โ
Demo messages created", :green
say "Use 'enhance-swarm communicate --status' to see them"
else
pending = communicator.pending_messages
recent = communicator.recent_messages(5)
say "\n๐ฌ Agent Communication Status:", :blue
say " Pending messages: #{pending.count}"
say " Recent messages: #{recent.count}"
if pending.any?
say "\n๐ Recent Messages:", :yellow
pending.first(3).each_with_index do |message, index|
say " #{index + 1}. #{message[:type]} from #{message[:role]}"
say " #{message[:content][0..60]}..."
end
else
say " No messages currently"
say "\nTry: enhance-swarm communicate --demo"
end
end
end
desc 'suggest', 'Get smart suggestions for next actions'
option :context, type: :string, desc: 'Additional context for suggestions'
def suggest
say "๐ง Analyzing project and generating smart suggestions...", :blue
context = {
git_status: { modified_files: 2, untracked_files: 1 },
project_files: { ruby_files: 15, test_files: 8 },
user_context: options[:context]
}
suggestions = SmartDefaults.get_suggestions(context)
if suggestions.empty?
say "โ
No suggestions at this time. Your project looks good!", :green
return
end
say "\n๐ก Smart Suggestions:\n", :yellow
suggestions.each_with_index do |suggestion, i|
priority_color = case suggestion[:priority]
when :high then :red
when :medium then :yellow
when :low then :blue
else :white
end
say "#{i + 1}. [#{suggestion[:priority].to_s.upcase}] #{suggestion[:description]}", priority_color
say " Command: #{suggestion[:command]}", :light_black if suggestion[:command]
say ""
end
end
desc 'recover', 'Intelligent error recovery and analysis'
option :analyze, type: :string, desc: 'Analyze specific error message'
option :stats, type: :boolean, desc: 'Show error recovery statistics'
option :demo, type: :boolean, desc: 'Demo error recovery features'
def recover
error_recovery = ErrorRecovery.instance
if options[:analyze]
say "๐ Analyzing error: #{options[:analyze]}", :blue
test_error = StandardError.new(options[:analyze])
analysis = error_recovery.analyze_error(test_error, { context: 'cli_demo' })
say "\n๐ Error Analysis:", :yellow
say " Type: #{analysis[:error][:type]}"
say " Auto-recoverable: #{analysis[:auto_recoverable] ? 'Yes' : 'No'}"
say " Suggestions: #{analysis[:suggestions].count}"
if analysis[:suggestions].any?
say "\n๐ก Recovery Suggestions:", :green
analysis[:suggestions].first(3).each_with_index do |suggestion, i|
description = suggestion['description'] || suggestion[:description]
say " #{i + 1}. #{description}"
end
end
elsif options[:stats]
stats = error_recovery.recovery_statistics
say "\n๐ Error Recovery Statistics:", :blue
say " Total errors processed: #{stats[:total_errors_processed]}"
say " Successful recoveries: #{stats[:successful_automatic_recoveries]}"
say " Success rate: #{stats[:recovery_success_rate]}%"
say " Patterns learned: #{stats[:recovery_patterns_learned]}"
elsif options[:demo]
say "๐ง Demo Error Recovery", :green
errors = [
'Connection timeout after 30 seconds',
'No such file or directory - missing.rb',
'Permission denied accessing /etc/hosts'
]
errors.each do |error_msg|
say "\n๐ Analyzing: #{error_msg}", :blue
test_error = StandardError.new(error_msg)
analysis = error_recovery.analyze_error(test_error)
say " Auto-recoverable: #{analysis[:auto_recoverable] ? 'โ
Yes' : 'โ No'}"
say " Suggestions: #{analysis[:suggestions].count}"
end
else
say "Please specify an action:", :yellow
say " --analyze 'error message' - Analyze specific error"
say " --stats - Show recovery statistics"
say " --demo - Demo error recovery features"
end
end
desc 'troubleshoot', 'Interactive troubleshooting assistant'
def troubleshoot
say "๐ง EnhanceSwarm Troubleshooting Assistant", :green
say "โ" * 50, :light_black
say "\n๐ Quick System Check:", :blue
begin
require 'thor'
say " โ
Thor gem available"
rescue LoadError
say " โ Thor gem missing"
end
begin
require 'colorize'
say " โ
Colorize gem available"
rescue LoadError
say " โ Colorize gem missing"
end
git_available = system('git --version > /dev/null 2>&1')
say " #{git_available ? 'โ
' : 'โ'} Git #{git_available ? 'available' : 'not found'}"
enhance_config = File.exist?('.enhance_swarm.yml')
say " #{enhance_config ? 'โ
' : 'โ'} Project config #{enhance_config ? 'found' : 'missing'}"
say "\n๐งช Testing Core Classes:", :blue
classes = %w[NotificationManager VisualDashboard SmartDefaults ErrorRecovery AgentCommunicator]
classes.each do |cls|
begin
klass = EnhanceSwarm.const_get(cls)
klass.instance if klass.respond_to?(:instance)
say " โ
#{cls} working"
rescue => e
say " โ #{cls} error: #{e.message}"
end
end
say "\nโ
Troubleshooting completed!", :green
say "If issues persist, check the README for setup instructions."
end
private
def discover_running_agents
[]
end
def load_specific_agents(agent_ids)
agent_ids.map do |id|
{
id: id,
role: 'backend',
status: 'running',
progress: rand(10..90),
start_time: Time.now - rand(60..3600),
pid: rand(1000..9999)
}
end
end
def create_demo_agents
[
{
id: 'backend-auth-123',
role: 'backend',
status: 'running',
progress: 75,
start_time: Time.now - 300,
pid: 1234
},
{
id: 'frontend-ui-456',
role: 'frontend',
status: 'completed',
progress: 100,
start_time: Time.now - 600,
pid: 5678
}
]
end
end
end
|