aidp 0.15.1 → 0.15.2

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.
@@ -1,403 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "tty-prompt"
4
- require_relative "ruby_maat_integration"
5
- require_relative "feature_analyzer"
6
-
7
- module Aidp
8
- module Analyze
9
- class Prioritizer
10
- def initialize(project_dir = Dir.pwd, prompt: TTY::Prompt.new)
11
- @project_dir = project_dir
12
- @code_maat = Aidp::Analyze::RubyMaatIntegration.new(project_dir, prompt: prompt)
13
- @feature_analyzer = Aidp::Analyze::FeatureAnalyzer.new(project_dir)
14
- end
15
-
16
- # Generate prioritized analysis recommendations based on ruby-maat data
17
- def generate_prioritized_recommendations
18
- # Get ruby-maat analysis data
19
- code_maat_data = @code_maat.run_comprehensive_analysis
20
-
21
- # Get feature analysis data
22
- features = @feature_analyzer.detect_features
23
-
24
- # Generate prioritized recommendations
25
- {
26
- high_priority: generate_high_priority_recommendations(code_maat_data, features),
27
- medium_priority: generate_medium_priority_recommendations(code_maat_data, features),
28
- low_priority: generate_low_priority_recommendations(code_maat_data, features),
29
- focus_areas: identify_focus_areas(code_maat_data, features),
30
- analysis_strategy: generate_analysis_strategy(code_maat_data, features)
31
- }
32
- end
33
-
34
- # Get high-priority analysis targets
35
- def get_high_priority_targets
36
- @code_maat.run_comprehensive_analysis
37
-
38
- high_priority = []
39
-
40
- # High churn + single author (knowledge silos)
41
- high_churn_files = @code_maat.get_high_churn_files(10)
42
- knowledge_silos = @code_maat.get_knowledge_silos
43
-
44
- high_churn_files.each do |churn_file|
45
- silo_file = knowledge_silos.find { |s| s[:file] == churn_file[:file] }
46
- next unless silo_file
47
-
48
- high_priority << {
49
- type: "knowledge_silo",
50
- file: churn_file[:file],
51
- changes: churn_file[:changes],
52
- author: silo_file[:authors].first,
53
- priority_score: calculate_priority_score(churn_file, silo_file),
54
- recommendation: "High churn file with single author - potential knowledge silo"
55
- }
56
- end
57
-
58
- # Tightly coupled files
59
- tightly_coupled = @code_maat.get_tightly_coupled_files(5)
60
- tightly_coupled.each do |coupling|
61
- high_priority << {
62
- type: "tight_coupling",
63
- file1: coupling[:file1],
64
- file2: coupling[:file2],
65
- shared_changes: coupling[:shared_changes],
66
- priority_score: coupling[:shared_changes] * 2,
67
- recommendation: "Tightly coupled files - consider refactoring to reduce coupling"
68
- }
69
- end
70
-
71
- high_priority.sort_by { |item| -item[:priority_score] }
72
- end
73
-
74
- # Get medium-priority analysis targets
75
- def get_medium_priority_targets
76
- code_maat_data = @code_maat.run_comprehensive_analysis
77
-
78
- medium_priority = []
79
-
80
- # High churn + multiple authors (coordination issues)
81
- high_churn_files = @code_maat.get_high_churn_files(5)
82
- multi_author_files = code_maat_data[:authorship][:files].select { |f| f[:author_count] > 1 }
83
-
84
- high_churn_files.each do |churn_file|
85
- multi_auth_file = multi_author_files.find { |m| m[:file] == churn_file[:file] }
86
- next unless multi_auth_file
87
-
88
- medium_priority << {
89
- type: "coordination_issue",
90
- file: churn_file[:file],
91
- changes: churn_file[:changes],
92
- authors: multi_auth_file[:authors],
93
- priority_score: calculate_priority_score(churn_file, multi_auth_file),
94
- recommendation: "High churn file with multiple authors - potential coordination issues"
95
- }
96
- end
97
-
98
- # Medium churn files
99
- medium_churn_files = code_maat_data[:churn][:files].select { |f| f[:changes] > 3 && f[:changes] <= 10 }
100
- medium_churn_files.each do |file|
101
- medium_priority << {
102
- type: "medium_churn",
103
- file: file[:file],
104
- changes: file[:changes],
105
- priority_score: file[:changes],
106
- recommendation: "Medium churn file - monitor for increasing complexity"
107
- }
108
- end
109
-
110
- medium_priority.sort_by { |item| -item[:priority_score] }
111
- end
112
-
113
- # Get low-priority analysis targets
114
- def get_low_priority_targets
115
- code_maat_data = @code_maat.run_comprehensive_analysis
116
-
117
- low_priority = []
118
-
119
- # Low churn files
120
- low_churn_files = code_maat_data[:churn][:files].select { |f| f[:changes] <= 3 }
121
- low_churn_files.each do |file|
122
- low_priority << {
123
- type: "low_churn",
124
- file: file[:file],
125
- changes: file[:changes],
126
- priority_score: file[:changes],
127
- recommendation: "Low churn file - stable, may not need immediate attention"
128
- }
129
- end
130
-
131
- low_priority.sort_by { |item| -item[:priority_score] }
132
- end
133
-
134
- # Identify focus areas for analysis
135
- def identify_focus_areas
136
- @code_maat.run_comprehensive_analysis
137
- @feature_analyzer.detect_features
138
-
139
- focus_areas = []
140
-
141
- # High churn areas
142
- high_churn_files = @code_maat.get_high_churn_files(8)
143
- high_churn_areas = group_files_by_directory(high_churn_files.map { |f| f[:file] })
144
-
145
- high_churn_areas.each do |area, files|
146
- focus_areas << {
147
- type: "high_churn_area",
148
- area: area,
149
- files: files,
150
- priority: "high",
151
- recommendation: "High churn area - focus analysis on #{area} directory"
152
- }
153
- end
154
-
155
- # Knowledge silo areas
156
- knowledge_silos = @code_maat.get_knowledge_silos
157
- silo_areas = group_files_by_directory(knowledge_silos.map { |f| f[:file] })
158
-
159
- silo_areas.each do |area, files|
160
- focus_areas << {
161
- type: "knowledge_silo_area",
162
- area: area,
163
- files: files,
164
- priority: "high",
165
- recommendation: "Knowledge silo area - #{area} has single-author files"
166
- }
167
- end
168
-
169
- # Coupling hotspots
170
- tightly_coupled = @code_maat.get_tightly_coupled_files(3)
171
- coupling_areas = identify_coupling_hotspots(tightly_coupled)
172
-
173
- coupling_areas.each do |area, couplings|
174
- focus_areas << {
175
- type: "coupling_hotspot",
176
- area: area,
177
- couplings: couplings,
178
- priority: "medium",
179
- recommendation: "Coupling hotspot - #{area} has tightly coupled files"
180
- }
181
- end
182
-
183
- focus_areas
184
- end
185
-
186
- # Generate analysis strategy recommendations
187
- def generate_analysis_strategy
188
- code_maat_data = @code_maat.run_comprehensive_analysis
189
- @feature_analyzer.detect_features
190
-
191
- {
192
- overall_approach: determine_overall_approach(code_maat_data),
193
- analysis_order: determine_analysis_order(code_maat_data),
194
- resource_allocation: determine_resource_allocation(code_maat_data),
195
- risk_assessment: assess_analysis_risks(code_maat_data),
196
- success_metrics: define_success_metrics(code_maat_data)
197
- }
198
- end
199
-
200
- private
201
-
202
- def generate_high_priority_recommendations(code_maat_data, features)
203
- recommendations = []
204
-
205
- # Knowledge silos
206
- knowledge_silos = @code_maat.get_knowledge_silos
207
- knowledge_silos.each do |silo|
208
- recommendations << {
209
- type: "knowledge_silo",
210
- target: silo[:file],
211
- priority: "high",
212
- rationale: "Single author with #{silo[:changes]} changes",
213
- action: "Document knowledge and consider pair programming",
214
- effort: "medium",
215
- impact: "high"
216
- }
217
- end
218
-
219
- # Tight coupling
220
- tightly_coupled = @code_maat.get_tightly_coupled_files(5)
221
- tightly_coupled.each do |coupling|
222
- recommendations << {
223
- type: "tight_coupling",
224
- target: "#{coupling[:file1]} ↔ #{coupling[:file2]}",
225
- priority: "high",
226
- rationale: "#{coupling[:shared_changes]} shared changes",
227
- action: "Refactor to reduce coupling",
228
- effort: "high",
229
- impact: "high"
230
- }
231
- end
232
-
233
- recommendations
234
- end
235
-
236
- def generate_medium_priority_recommendations(code_maat_data, features)
237
- recommendations = []
238
-
239
- # High churn with multiple authors
240
- high_churn_multi_author = code_maat_data[:churn][:files].select do |file|
241
- file[:changes] > 5 &&
242
- (code_maat_data[:authorship][:files].find { |a| a[:file] == file[:file] }&.dig(:author_count)&.> 1)
243
- end
244
-
245
- high_churn_multi_author.each do |file|
246
- recommendations << {
247
- type: "coordination_issue",
248
- target: file[:file],
249
- priority: "medium",
250
- rationale: "High churn (#{file[:changes]} changes) with multiple authors",
251
- action: "Improve coordination and communication",
252
- effort: "medium",
253
- impact: "medium"
254
- }
255
- end
256
-
257
- recommendations
258
- end
259
-
260
- def generate_low_priority_recommendations(code_maat_data, features)
261
- recommendations = []
262
-
263
- # Stable files
264
- stable_files = code_maat_data[:churn][:files].select { |f| f[:changes] <= 2 }
265
- stable_files.each do |file|
266
- recommendations << {
267
- type: "stable_file",
268
- target: file[:file],
269
- priority: "low",
270
- rationale: "Low churn (#{file[:changes]} changes) - stable",
271
- action: "Monitor for changes",
272
- effort: "low",
273
- impact: "low"
274
- }
275
- end
276
-
277
- recommendations
278
- end
279
-
280
- def calculate_priority_score(churn_file, authorship_file)
281
- base_score = churn_file[:changes]
282
-
283
- # Adjust for authorship patterns
284
- if authorship_file[:author_count] == 1
285
- base_score *= 1.5 # Knowledge silo penalty
286
- elsif authorship_file[:author_count] > 3
287
- base_score *= 1.2 # Coordination complexity penalty
288
- end
289
-
290
- base_score
291
- end
292
-
293
- def group_files_by_directory(files)
294
- grouped = {}
295
-
296
- files.each do |file|
297
- dir = File.dirname(file)
298
- grouped[dir] ||= []
299
- grouped[dir] << file
300
- end
301
-
302
- grouped
303
- end
304
-
305
- def identify_coupling_hotspots(couplings)
306
- hotspots = {}
307
-
308
- couplings.each do |coupling|
309
- dir1 = File.dirname(coupling[:file1])
310
- dir2 = File.dirname(coupling[:file2])
311
-
312
- # Group by common directory or create cross-directory coupling
313
- if dir1 == dir2
314
- hotspots[dir1] ||= []
315
- hotspots[dir1] << coupling
316
- else
317
- cross_dir = "#{dir1} ↔ #{dir2}"
318
- hotspots[cross_dir] ||= []
319
- hotspots[cross_dir] << coupling
320
- end
321
- end
322
-
323
- hotspots
324
- end
325
-
326
- def determine_overall_approach(code_maat_data)
327
- total_files = code_maat_data[:churn][:total_files]
328
- high_churn_count = code_maat_data[:churn][:files].count { |f| f[:changes] > 10 }
329
- knowledge_silos = code_maat_data[:authorship][:files_with_single_author]
330
-
331
- if high_churn_count > total_files * 0.3
332
- "aggressive_refactoring"
333
- elsif knowledge_silos > total_files * 0.2
334
- "knowledge_transfer_focused"
335
- elsif code_maat_data[:coupling][:average_coupling] > 5
336
- "coupling_reduction_focused"
337
- else
338
- "incremental_improvement"
339
- end
340
- end
341
-
342
- def determine_analysis_order(code_maat_data)
343
- order = []
344
-
345
- # Start with highest impact areas
346
- order << "knowledge_silos" if code_maat_data[:authorship][:files_with_single_author] > 0
347
-
348
- order << "coupling_analysis" if code_maat_data[:coupling][:average_coupling] > 3
349
-
350
- order << "high_churn_analysis" if code_maat_data[:churn][:files].any? { |f| f[:changes] > 15 }
351
-
352
- order << "general_quality_analysis"
353
- order
354
- end
355
-
356
- def determine_resource_allocation(code_maat_data)
357
- total_files = code_maat_data[:churn][:total_files]
358
-
359
- {
360
- high_priority_percentage: 20,
361
- medium_priority_percentage: 50,
362
- low_priority_percentage: 30,
363
- estimated_effort_hours: total_files * 0.5,
364
- recommended_team_size: [total_files / 50, 1].max
365
- }
366
- end
367
-
368
- def assess_analysis_risks(code_maat_data)
369
- risks = []
370
-
371
- if code_maat_data[:authorship][:files_with_single_author] > code_maat_data[:churn][:total_files] * 0.3
372
- risks << {
373
- type: "knowledge_silo_risk",
374
- severity: "high",
375
- description: "High percentage of single-author files indicates knowledge silos",
376
- mitigation: "Implement knowledge sharing and documentation practices"
377
- }
378
- end
379
-
380
- if code_maat_data[:coupling][:average_coupling] > 8
381
- risks << {
382
- type: "coupling_risk",
383
- severity: "medium",
384
- description: "High average coupling indicates tight dependencies",
385
- mitigation: "Focus on reducing coupling through refactoring"
386
- }
387
- end
388
-
389
- risks
390
- end
391
-
392
- def define_success_metrics(code_maat_data)
393
- {
394
- knowledge_silo_reduction: "Reduce single-author files by 50%",
395
- coupling_reduction: "Reduce average coupling by 30%",
396
- churn_stabilization: "Reduce high-churn files by 25%",
397
- documentation_coverage: "Achieve 80% documentation coverage",
398
- test_coverage: "Achieve 90% test coverage"
399
- }
400
- end
401
- end
402
- end
403
- end