adre-cli 0.1.0__py3-none-any.whl

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 (48) hide show
  1. adre/__init__.py +5 -0
  2. adre/analyzers/__init__.py +1 -0
  3. adre/analyzers/architecture.py +253 -0
  4. adre/analyzers/findings.py +457 -0
  5. adre/analyzers/inference.py +163 -0
  6. adre/cli.py +923 -0
  7. adre/core/__init__.py +1 -0
  8. adre/core/accepted.py +225 -0
  9. adre/core/adaptive.py +221 -0
  10. adre/core/baseline.py +1165 -0
  11. adre/core/config.py +60 -0
  12. adre/core/decision_engine.py +361 -0
  13. adre/core/declared.py +313 -0
  14. adre/core/evolution_intelligence.py +390 -0
  15. adre/core/explainer.py +413 -0
  16. adre/core/git_intelligence.py +392 -0
  17. adre/core/github_check.py +212 -0
  18. adre/core/incremental.py +288 -0
  19. adre/core/layers.py +306 -0
  20. adre/core/pr_intelligence.py +261 -0
  21. adre/core/pr_review.py +454 -0
  22. adre/core/prioritization.py +196 -0
  23. adre/core/project.py +41 -0
  24. adre/core/refactor_intelligence.py +201 -0
  25. adre/core/repositories.py +312 -0
  26. adre/core/review.py +96 -0
  27. adre/core/rules_shared.py +75 -0
  28. adre/core/sarif.py +141 -0
  29. adre/core/scope.py +141 -0
  30. adre/core/snapshots.py +242 -0
  31. adre/core/stability_intelligence.py +361 -0
  32. adre/graph/__init__.py +0 -0
  33. adre/graph/dependencies.py +379 -0
  34. adre/parsers/__init__.py +87 -0
  35. adre/parsers/go.py +140 -0
  36. adre/parsers/javascript.py +364 -0
  37. adre/parsers/jvm.py +127 -0
  38. adre/parsers/python.py +153 -0
  39. adre/reports/__init__.py +1 -0
  40. adre/reports/architecture.py +349 -0
  41. adre/rules.py +12 -0
  42. adre/web.py +3731 -0
  43. adre_cli-0.1.0.dist-info/METADATA +343 -0
  44. adre_cli-0.1.0.dist-info/RECORD +48 -0
  45. adre_cli-0.1.0.dist-info/WHEEL +5 -0
  46. adre_cli-0.1.0.dist-info/entry_points.txt +2 -0
  47. adre_cli-0.1.0.dist-info/licenses/LICENSE +202 -0
  48. adre_cli-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,390 @@
1
+ from collections import defaultdict
2
+
3
+ from adre.core.snapshots import compare_snapshot_data
4
+ from adre.graph.dependencies import dependency_graph_edges
5
+
6
+
7
+ SCORE_DROP_THRESHOLD = 10
8
+ DEPENDENCY_EXPLOSION_THRESHOLD = 5
9
+
10
+
11
+ def short_commit(commit_hash):
12
+ if not commit_hash:
13
+ return "unknown"
14
+ return commit_hash[:12]
15
+
16
+
17
+ def snapshot_hotspots(snapshot):
18
+ return snapshot.get("hotspots", snapshot.get("hotspot_files", [])) or []
19
+
20
+
21
+ def snapshot_score(snapshot):
22
+ return snapshot.get("architecture_score", 0)
23
+
24
+
25
+ def snapshot_confidence(snapshot):
26
+ return snapshot.get("confidence", snapshot.get("architecture_confidence", 0))
27
+
28
+
29
+ def file_subsystem(file_path):
30
+ if not file_path:
31
+ return "unknown"
32
+ normalized = file_path.replace("\\", "/")
33
+ parts = [part for part in normalized.split("/") if part]
34
+ if len(parts) > 1:
35
+ return f"{parts[0]}/"
36
+ return "root/"
37
+
38
+
39
+ def collect_issue_files(issues):
40
+ files = []
41
+ for issue in issues:
42
+ file = issue.get("file")
43
+ imported = issue.get("imported")
44
+ if file:
45
+ files.append(file)
46
+ if imported and imported.endswith(".py") and " -> " not in imported:
47
+ files.append(imported)
48
+ return files
49
+
50
+
51
+ def collect_cycle_files(cycles):
52
+ files = []
53
+ for cycle in cycles:
54
+ files.extend(file for file in cycle if file)
55
+ return files
56
+
57
+
58
+ def dependency_edge_count(snapshot):
59
+ return len(dependency_graph_edges(snapshot.get("dependency_graph", {})))
60
+
61
+
62
+ def build_evolution_timeline(git_snapshots):
63
+ timeline = []
64
+ for snapshot in git_snapshots:
65
+ timeline.append({
66
+ "commit": snapshot.get("commit_hash"),
67
+ "timestamp": snapshot.get("timestamp"),
68
+ "architecture_score": snapshot_score(snapshot),
69
+ "issue_count": len(snapshot.get("issues", [])),
70
+ "cycle_count": len(snapshot.get("cycles", [])),
71
+ "hotspot_count": len(snapshot_hotspots(snapshot)),
72
+ "dependency_count": dependency_edge_count(snapshot),
73
+ "architecture_type": snapshot.get("architecture_type"),
74
+ "confidence": snapshot_confidence(snapshot),
75
+ })
76
+ return timeline
77
+
78
+
79
+ def calculate_trend(scores):
80
+ if len(scores) < 2:
81
+ return "stable"
82
+ delta = scores[-1] - scores[0]
83
+ if delta >= 5:
84
+ return "improving"
85
+ if delta <= -5:
86
+ return "degrading"
87
+ return "stable"
88
+
89
+
90
+ def calculate_stability_score(scores):
91
+ if len(scores) < 2:
92
+ return 100
93
+ total_delta = sum(abs(scores[index] - scores[index - 1]) for index in range(1, len(scores)))
94
+ average_delta = total_delta / (len(scores) - 1)
95
+ return max(0, min(100, int(round(100 - average_delta * 4))))
96
+
97
+
98
+ def event_severity(score_delta=0, new_cycles=0, dependency_delta=0, type_shift=False):
99
+ if new_cycles or score_delta <= -20:
100
+ return "critical"
101
+ if score_delta <= -SCORE_DROP_THRESHOLD or dependency_delta >= DEPENDENCY_EXPLOSION_THRESHOLD or type_shift:
102
+ return "high"
103
+ if score_delta < 0 or dependency_delta > 0:
104
+ return "medium"
105
+ return "low"
106
+
107
+
108
+ def detect_drift_events(git_snapshots):
109
+ events = []
110
+ first_cycle_seen = any(snapshot.get("cycles") for snapshot in git_snapshots[:1])
111
+ first_hotspot_seen = bool(snapshot_hotspots(git_snapshots[0])) if git_snapshots else False
112
+
113
+ for index in range(1, len(git_snapshots)):
114
+ before = git_snapshots[index - 1]
115
+ after = git_snapshots[index]
116
+ comparison = compare_snapshot_data(
117
+ {**before, "file": before.get("commit_hash")},
118
+ {**after, "file": after.get("commit_hash")},
119
+ )
120
+ score_delta = snapshot_score(after) - snapshot_score(before)
121
+ before_edges = dependency_edge_count(before)
122
+ after_edges = dependency_edge_count(after)
123
+ dependency_delta = after_edges - before_edges
124
+ new_cycles = comparison.get("new_cycles", [])
125
+ before_hotspots = {item.get("file") for item in snapshot_hotspots(before)}
126
+ after_hotspots = {item.get("file") for item in snapshot_hotspots(after)}
127
+ new_hotspots = sorted(file for file in after_hotspots - before_hotspots if file)
128
+ type_shift = before.get("architecture_type") != after.get("architecture_type")
129
+
130
+ if new_cycles and not first_cycle_seen:
131
+ events.append({
132
+ "commit": after.get("commit_hash"),
133
+ "timestamp": after.get("timestamp"),
134
+ "event": "first cycle introduced",
135
+ "severity": "critical",
136
+ "details": f"{len(new_cycles)} new cycle(s) appeared.",
137
+ })
138
+ first_cycle_seen = True
139
+ elif new_cycles:
140
+ events.append({
141
+ "commit": after.get("commit_hash"),
142
+ "timestamp": after.get("timestamp"),
143
+ "event": "cycle introduced",
144
+ "severity": "critical",
145
+ "details": f"{len(new_cycles)} new cycle(s) appeared.",
146
+ })
147
+
148
+ if new_hotspots and not first_hotspot_seen:
149
+ events.append({
150
+ "commit": after.get("commit_hash"),
151
+ "timestamp": after.get("timestamp"),
152
+ "event": "first hotspot created",
153
+ "severity": "high",
154
+ "details": ", ".join(new_hotspots[:5]),
155
+ })
156
+ first_hotspot_seen = True
157
+ elif new_hotspots:
158
+ events.append({
159
+ "commit": after.get("commit_hash"),
160
+ "timestamp": after.get("timestamp"),
161
+ "event": "hotspot created",
162
+ "severity": "medium",
163
+ "details": ", ".join(new_hotspots[:5]),
164
+ })
165
+
166
+ if score_delta <= -SCORE_DROP_THRESHOLD:
167
+ events.append({
168
+ "commit": after.get("commit_hash"),
169
+ "timestamp": after.get("timestamp"),
170
+ "event": "architecture score regression",
171
+ "severity": event_severity(score_delta=score_delta),
172
+ "details": f"Architecture score dropped by {abs(score_delta)} points.",
173
+ })
174
+
175
+ if dependency_delta >= DEPENDENCY_EXPLOSION_THRESHOLD:
176
+ events.append({
177
+ "commit": after.get("commit_hash"),
178
+ "timestamp": after.get("timestamp"),
179
+ "event": "dependency explosion",
180
+ "severity": event_severity(dependency_delta=dependency_delta),
181
+ "details": f"Dependency edge count increased by {dependency_delta}.",
182
+ })
183
+
184
+ if type_shift:
185
+ events.append({
186
+ "commit": after.get("commit_hash"),
187
+ "timestamp": after.get("timestamp"),
188
+ "event": "architecture type shift",
189
+ "severity": "high",
190
+ "details": (
191
+ f"{before.get('architecture_type') or 'unknown'} -> "
192
+ f"{after.get('architecture_type') or 'unknown'}"
193
+ ),
194
+ })
195
+
196
+ return sorted(events, key=lambda item: (item.get("timestamp") or "", item.get("event") or ""))
197
+
198
+
199
+ def identify_repeat_offenders(git_snapshots):
200
+ file_scores = defaultdict(int)
201
+ reasons = defaultdict(lambda: defaultdict(int))
202
+
203
+ for snapshot in git_snapshots:
204
+ for file in collect_cycle_files(snapshot.get("cycles", [])):
205
+ file_scores[file] += 12
206
+ reasons[file]["cycle involvement"] += 1
207
+ for file in collect_issue_files(snapshot.get("issues", [])):
208
+ file_scores[file] += 7
209
+ reasons[file]["layer violation"] += 1
210
+ for hotspot in snapshot_hotspots(snapshot):
211
+ file = hotspot.get("file")
212
+ if not file:
213
+ continue
214
+ file_scores[file] += 6 + min(10, hotspot.get("dependency_count", 0) * 2)
215
+ reasons[file]["hotspot"] += 1
216
+
217
+ for index in range(1, len(git_snapshots)):
218
+ before = git_snapshots[index - 1]
219
+ after = git_snapshots[index]
220
+ if snapshot_score(after) >= snapshot_score(before):
221
+ continue
222
+ comparison = compare_snapshot_data(
223
+ {**before, "file": before.get("commit_hash")},
224
+ {**after, "file": after.get("commit_hash")},
225
+ )
226
+ files = set()
227
+ files.update(collect_cycle_files(comparison.get("new_cycles", [])))
228
+ files.update(collect_issue_files(comparison.get("new_issues_introduced", [])))
229
+ for file in files:
230
+ file_scores[file] += 10
231
+ reasons[file]["regression involvement"] += 1
232
+
233
+ offenders = []
234
+ for file, score in file_scores.items():
235
+ offenders.append({
236
+ "file": file,
237
+ "offender_score": min(100, score),
238
+ "reasons": [
239
+ f"{reason} ({count})"
240
+ for reason, count in sorted(reasons[file].items())
241
+ ],
242
+ })
243
+
244
+ return sorted(offenders, key=lambda item: (-item["offender_score"], item["file"]))
245
+
246
+
247
+ def subsystem_snapshot_metrics(snapshot):
248
+ metrics = defaultdict(lambda: {
249
+ "issue_count": 0,
250
+ "cycle_involvement": 0,
251
+ "dependency_count": 0,
252
+ "hotspot_count": 0,
253
+ })
254
+
255
+ for issue in snapshot.get("issues", []):
256
+ metrics[file_subsystem(issue.get("file"))]["issue_count"] += 1
257
+
258
+ for file in collect_cycle_files(snapshot.get("cycles", [])):
259
+ metrics[file_subsystem(file)]["cycle_involvement"] += 1
260
+
261
+ for source, target in dependency_graph_edges(snapshot.get("dependency_graph", {})):
262
+ metrics[file_subsystem(source)]["dependency_count"] += 1
263
+ metrics[file_subsystem(target)]["dependency_count"] += 1
264
+
265
+ for hotspot in snapshot_hotspots(snapshot):
266
+ metrics[file_subsystem(hotspot.get("file"))]["hotspot_count"] += 1
267
+
268
+ return metrics
269
+
270
+
271
+ def subsystem_risk(metrics):
272
+ return (
273
+ metrics.get("issue_count", 0) * 10
274
+ + metrics.get("cycle_involvement", 0) * 12
275
+ + metrics.get("hotspot_count", 0) * 8
276
+ + metrics.get("dependency_count", 0)
277
+ )
278
+
279
+
280
+ def build_subsystem_health(git_snapshots):
281
+ if not git_snapshots:
282
+ return {}
283
+
284
+ first_metrics = subsystem_snapshot_metrics(git_snapshots[0])
285
+ last_metrics = subsystem_snapshot_metrics(git_snapshots[-1])
286
+ all_subsystems = sorted(set(first_metrics) | set(last_metrics))
287
+ health = {}
288
+
289
+ for subsystem in all_subsystems:
290
+ first = first_metrics[subsystem]
291
+ last = last_metrics[subsystem]
292
+ risk_delta = subsystem_risk(last) - subsystem_risk(first)
293
+
294
+ if risk_delta >= 10:
295
+ trend = "degrading"
296
+ elif risk_delta <= -10:
297
+ trend = "improving"
298
+ else:
299
+ trend = "stable"
300
+
301
+ health[subsystem] = {
302
+ "trend": trend,
303
+ "issue_growth": last["issue_count"] - first["issue_count"],
304
+ "cycle_involvement": last["cycle_involvement"],
305
+ "dependency_growth": last["dependency_count"] - first["dependency_count"],
306
+ "hotspot_growth": last["hotspot_count"] - first["hotspot_count"],
307
+ "risk_delta": risk_delta,
308
+ }
309
+
310
+ return health
311
+
312
+
313
+ def discover_root_causes(git_snapshots):
314
+ if len(git_snapshots) < 2:
315
+ return ["Not enough git history is available to infer architecture root causes."]
316
+
317
+ subsystem_regressions = defaultdict(int)
318
+ total_regressions = 0
319
+
320
+ for index in range(1, len(git_snapshots)):
321
+ before = git_snapshots[index - 1]
322
+ after = git_snapshots[index]
323
+ if snapshot_score(after) >= snapshot_score(before):
324
+ continue
325
+ total_regressions += 1
326
+ comparison = compare_snapshot_data(
327
+ {**before, "file": before.get("commit_hash")},
328
+ {**after, "file": after.get("commit_hash")},
329
+ )
330
+ files = set()
331
+ files.update(collect_cycle_files(comparison.get("new_cycles", [])))
332
+ files.update(collect_issue_files(comparison.get("new_issues_introduced", [])))
333
+ for growth in comparison.get("dependency_growth_per_file", []):
334
+ if growth.get("net_dependency_delta", 0) > 0:
335
+ files.add(growth.get("file"))
336
+
337
+ if not files:
338
+ subsystem_regressions["unknown"] += 1
339
+ continue
340
+
341
+ for subsystem in {file_subsystem(file) for file in files if file}:
342
+ subsystem_regressions[subsystem] += 1
343
+
344
+ if not total_regressions:
345
+ return ["No recurring architecture regression source is visible in the analyzed history."]
346
+
347
+ insights = []
348
+ total_subsystem_contributions = max(1, sum(subsystem_regressions.values()))
349
+ for subsystem, count in sorted(subsystem_regressions.items(), key=lambda item: (-item[1], item[0]))[:3]:
350
+ percentage = int(round((count / total_subsystem_contributions) * 100))
351
+ insights.append(
352
+ f"The {subsystem} subsystem accounts for {percentage}% of architecture regressions."
353
+ )
354
+
355
+ return insights
356
+
357
+
358
+ def analyze_architecture_evolution(git_snapshots):
359
+ timeline = build_evolution_timeline(git_snapshots)
360
+ scores = [item["architecture_score"] for item in timeline]
361
+ subsystem_health = build_subsystem_health(git_snapshots)
362
+ degrading_subsystems = [
363
+ {"subsystem": subsystem, **data}
364
+ for subsystem, data in sorted(
365
+ subsystem_health.items(),
366
+ key=lambda item: (-item[1].get("risk_delta", 0), item[0]),
367
+ )
368
+ if data.get("trend") == "degrading"
369
+ ]
370
+ improving_subsystems = [
371
+ {"subsystem": subsystem, **data}
372
+ for subsystem, data in sorted(
373
+ subsystem_health.items(),
374
+ key=lambda item: (item[1].get("risk_delta", 0), item[0]),
375
+ )
376
+ if data.get("trend") == "improving"
377
+ ]
378
+
379
+ return {
380
+ "trend": calculate_trend(scores),
381
+ "stability_score": calculate_stability_score(scores),
382
+ "architecture_timeline": timeline,
383
+ "timeline": timeline,
384
+ "degrading_subsystems": degrading_subsystems,
385
+ "improving_subsystems": improving_subsystems,
386
+ "drift_events": detect_drift_events(git_snapshots),
387
+ "repeat_offenders": identify_repeat_offenders(git_snapshots),
388
+ "subsystem_health": subsystem_health,
389
+ "root_causes": discover_root_causes(git_snapshots),
390
+ }