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,361 @@
1
+ from collections import defaultdict, deque
2
+
3
+ from adre.core.git_intelligence import extract_git_snapshots
4
+ from adre.core.snapshots import compare_snapshot_data
5
+ from adre.graph.dependencies import build_graph, dependency_graph_edges
6
+
7
+
8
+ def clamp_score(value):
9
+ return max(0, min(100, int(round(value))))
10
+
11
+
12
+ def file_subsystem(file_path):
13
+ if not file_path:
14
+ return "unknown/"
15
+ normalized = file_path.replace("\\", "/")
16
+ parts = [part for part in normalized.split("/") if part]
17
+ if len(parts) > 1:
18
+ return f"{parts[0]}/"
19
+ return "root/"
20
+
21
+
22
+ def snapshot_hotspots(snapshot):
23
+ return snapshot.get("hotspots", snapshot.get("hotspot_files", [])) or []
24
+
25
+
26
+ def collect_cycle_files(cycles):
27
+ files = []
28
+ seen = set()
29
+ for cycle in cycles:
30
+ for file in cycle:
31
+ if file and file not in seen:
32
+ seen.add(file)
33
+ files.append(file)
34
+ return files
35
+
36
+
37
+ def collect_issue_files(issues):
38
+ files = []
39
+ for issue in issues:
40
+ file = issue.get("file")
41
+ imported = issue.get("imported")
42
+ if file:
43
+ files.append(file)
44
+ if imported and imported.endswith(".py") and " -> " not in imported:
45
+ files.append(imported)
46
+ return files
47
+
48
+
49
+ def compare_git_snapshots(before, after):
50
+ return compare_snapshot_data(
51
+ {**before, "file": before.get("commit_hash")},
52
+ {**after, "file": after.get("commit_hash")},
53
+ )
54
+
55
+
56
+ def recurrence_counts(git_snapshots):
57
+ counts = defaultdict(lambda: {
58
+ "issue_recurrence": 0,
59
+ "hotspot_recurrence": 0,
60
+ "cycle_recurrence": 0,
61
+ "drift_participation": 0,
62
+ })
63
+
64
+ for snapshot in git_snapshots:
65
+ for file in collect_issue_files(snapshot.get("issues", [])):
66
+ counts[file]["issue_recurrence"] += 1
67
+ for file in collect_cycle_files(snapshot.get("cycles", [])):
68
+ counts[file]["cycle_recurrence"] += 1
69
+ for hotspot in snapshot_hotspots(snapshot):
70
+ file = hotspot.get("file")
71
+ if file:
72
+ counts[file]["hotspot_recurrence"] += 1
73
+
74
+ for index in range(1, len(git_snapshots)):
75
+ before = git_snapshots[index - 1]
76
+ after = git_snapshots[index]
77
+ if after.get("architecture_score", 0) >= before.get("architecture_score", 0):
78
+ continue
79
+
80
+ comparison = compare_git_snapshots(before, after)
81
+ files = set()
82
+ files.update(collect_issue_files(comparison.get("new_issues_introduced", [])))
83
+ files.update(collect_cycle_files(comparison.get("new_cycles", [])))
84
+ for growth in comparison.get("dependency_growth_per_file", []):
85
+ if growth.get("net_dependency_delta", 0) > 0 and growth.get("file"):
86
+ files.add(growth["file"])
87
+
88
+ for file in files:
89
+ counts[file]["drift_participation"] += 1
90
+
91
+ return counts
92
+
93
+
94
+ def file_volatility_score(counts):
95
+ return clamp_score(
96
+ counts.get("issue_recurrence", 0) * 9
97
+ + counts.get("hotspot_recurrence", 0) * 8
98
+ + counts.get("cycle_recurrence", 0) * 14
99
+ + counts.get("drift_participation", 0) * 16
100
+ )
101
+
102
+
103
+ def build_volatile_files(git_snapshots):
104
+ counts = recurrence_counts(git_snapshots)
105
+ files = []
106
+ for file, file_counts in counts.items():
107
+ score = file_volatility_score(file_counts)
108
+ if score <= 0:
109
+ continue
110
+ reasons = []
111
+ for key, label in [
112
+ ("issue_recurrence", "issue recurrence"),
113
+ ("hotspot_recurrence", "hotspot recurrence"),
114
+ ("cycle_recurrence", "cycle recurrence"),
115
+ ("drift_participation", "drift participation"),
116
+ ]:
117
+ if file_counts.get(key, 0):
118
+ reasons.append(f"{label} ({file_counts[key]})")
119
+ files.append({
120
+ "file": file,
121
+ "volatility_score": score,
122
+ "reasons": reasons,
123
+ })
124
+
125
+ return sorted(files, key=lambda item: (-item["volatility_score"], item["file"]))
126
+
127
+
128
+ def all_project_files(git_snapshots):
129
+ files = set()
130
+ for snapshot in git_snapshots:
131
+ files.update(snapshot.get("dependency_graph", {}).keys())
132
+ return files
133
+
134
+
135
+ def build_stable_files(git_snapshots, volatile_files):
136
+ volatile_by_file = {item["file"]: item for item in volatile_files}
137
+ stable = []
138
+ for file in sorted(all_project_files(git_snapshots)):
139
+ volatility = volatile_by_file.get(file, {}).get("volatility_score", 0)
140
+ if volatility <= 15:
141
+ stable.append({
142
+ "file": file,
143
+ "stability_score": 100 - volatility,
144
+ "reasons": ["low architectural recurrence"],
145
+ })
146
+ return sorted(stable, key=lambda item: (-item["stability_score"], item["file"]))
147
+
148
+
149
+ def subsystem_metrics(git_snapshots):
150
+ metrics = defaultdict(lambda: {
151
+ "issue_count": 0,
152
+ "cycle_involvement": 0,
153
+ "hotspot_count": 0,
154
+ "regression_count": 0,
155
+ "dependency_growth": 0,
156
+ })
157
+
158
+ for snapshot in git_snapshots:
159
+ for file in collect_issue_files(snapshot.get("issues", [])):
160
+ metrics[file_subsystem(file)]["issue_count"] += 1
161
+ for file in collect_cycle_files(snapshot.get("cycles", [])):
162
+ metrics[file_subsystem(file)]["cycle_involvement"] += 1
163
+ for hotspot in snapshot_hotspots(snapshot):
164
+ file = hotspot.get("file")
165
+ if file:
166
+ metrics[file_subsystem(file)]["hotspot_count"] += 1
167
+
168
+ for index in range(1, len(git_snapshots)):
169
+ before = git_snapshots[index - 1]
170
+ after = git_snapshots[index]
171
+ comparison = compare_git_snapshots(before, after)
172
+ if after.get("architecture_score", 0) < before.get("architecture_score", 0):
173
+ touched = set()
174
+ touched.update(collect_issue_files(comparison.get("new_issues_introduced", [])))
175
+ touched.update(collect_cycle_files(comparison.get("new_cycles", [])))
176
+ for file in touched:
177
+ metrics[file_subsystem(file)]["regression_count"] += 1
178
+
179
+ for growth in comparison.get("dependency_growth_per_file", []):
180
+ if growth.get("net_dependency_delta", 0) > 0 and growth.get("file"):
181
+ metrics[file_subsystem(growth["file"])]["dependency_growth"] += growth["net_dependency_delta"]
182
+
183
+ return metrics
184
+
185
+
186
+ def subsystem_fragility_score(metrics):
187
+ return clamp_score(
188
+ metrics.get("issue_count", 0) * 7
189
+ + metrics.get("cycle_involvement", 0) * 10
190
+ + metrics.get("hotspot_count", 0) * 8
191
+ + metrics.get("regression_count", 0) * 14
192
+ + metrics.get("dependency_growth", 0) * 4
193
+ )
194
+
195
+
196
+ def subsystem_trend(metrics):
197
+ pressure = (
198
+ metrics.get("regression_count", 0)
199
+ + metrics.get("dependency_growth", 0)
200
+ + metrics.get("cycle_involvement", 0)
201
+ )
202
+ if pressure >= 5:
203
+ return "degrading"
204
+ if pressure <= 1 and metrics.get("issue_count", 0) <= 1:
205
+ return "stable"
206
+ return "watch"
207
+
208
+
209
+ def build_fragile_subsystems(git_snapshots):
210
+ fragile = []
211
+ for subsystem, metrics in subsystem_metrics(git_snapshots).items():
212
+ score = subsystem_fragility_score(metrics)
213
+ if score <= 0:
214
+ continue
215
+ fragile.append({
216
+ "subsystem": subsystem,
217
+ "fragility_score": score,
218
+ "trend": subsystem_trend(metrics),
219
+ "issue_density": metrics.get("issue_count", 0),
220
+ "regression_frequency": metrics.get("regression_count", 0),
221
+ "dependency_growth": metrics.get("dependency_growth", 0),
222
+ "cycle_involvement": metrics.get("cycle_involvement", 0),
223
+ })
224
+ return sorted(fragile, key=lambda item: (-item["fragility_score"], item["subsystem"]))
225
+
226
+
227
+ def build_resilient_subsystems(git_snapshots, fragile_subsystems):
228
+ fragile_by_name = {item["subsystem"]: item for item in fragile_subsystems}
229
+ subsystems = {file_subsystem(file) for file in all_project_files(git_snapshots)}
230
+ resilient = []
231
+ for subsystem in sorted(subsystems):
232
+ fragility = fragile_by_name.get(subsystem, {}).get("fragility_score", 0)
233
+ if fragility <= 25:
234
+ resilient.append({
235
+ "subsystem": subsystem,
236
+ "resilience_score": 100 - fragility,
237
+ "trend": "stable",
238
+ })
239
+ return sorted(resilient, key=lambda item: (-item["resilience_score"], item["subsystem"]))
240
+
241
+
242
+ def reverse_graph(graph):
243
+ reversed_graph = defaultdict(set)
244
+ for source, targets in graph.items():
245
+ reversed_graph[source] |= set()
246
+ for target in targets:
247
+ reversed_graph[target].add(source)
248
+ return reversed_graph
249
+
250
+
251
+ def transitive_dependents(file, graph):
252
+ reversed_graph = reverse_graph(graph)
253
+ seen = set()
254
+ queue = deque(reversed_graph.get(file, set()))
255
+ while queue:
256
+ current = queue.popleft()
257
+ if current in seen:
258
+ continue
259
+ seen.add(current)
260
+ queue.extend(reversed_graph.get(current, set()) - seen)
261
+ return seen
262
+
263
+
264
+ def blast_radius_level(score):
265
+ if score >= 70:
266
+ return "high"
267
+ if score >= 35:
268
+ return "medium"
269
+ return "low"
270
+
271
+
272
+ def calculate_blast_radius(file, dependency_graph=None, hotspot_files=None):
273
+ dependency_graph = dependency_graph or {}
274
+ hotspot_files = hotspot_files or []
275
+ graph = build_graph(dependency_graph) if dependency_graph else {}
276
+ inbound_count = sum(1 for targets in graph.values() if file in targets)
277
+ transitive_count = len(transitive_dependents(file, graph)) if graph else 0
278
+ hotspot = any(item.get("file") == file for item in hotspot_files)
279
+ score = clamp_score(inbound_count * 18 + transitive_count * 10 + (25 if hotspot else 0))
280
+ return {
281
+ "file": file,
282
+ "blast_radius": blast_radius_level(score),
283
+ "blast_radius_score": score,
284
+ "inbound_dependencies": inbound_count,
285
+ "transitive_dependents": transitive_count,
286
+ "hotspot": hotspot,
287
+ }
288
+
289
+
290
+ def build_blast_radius_ranking(git_snapshots):
291
+ if not git_snapshots:
292
+ return []
293
+ latest = git_snapshots[-1]
294
+ dependency_graph = latest.get("dependency_graph", {})
295
+ hotspot_files = snapshot_hotspots(latest)
296
+ ranking = [
297
+ calculate_blast_radius(file, dependency_graph, hotspot_files)
298
+ for file in dependency_graph
299
+ ]
300
+ return sorted(ranking, key=lambda item: (-item["blast_radius_score"], item["file"]))
301
+
302
+
303
+ def governance_insights(git_snapshots, fragile_subsystems, volatile_files):
304
+ insights = []
305
+ total_fragility = sum(item["fragility_score"] for item in fragile_subsystems)
306
+ if fragile_subsystems and total_fragility:
307
+ top = fragile_subsystems[0]
308
+ percentage = int(round((top["fragility_score"] / total_fragility) * 100))
309
+ insights.append(f"{top['subsystem']} accounts for {percentage}% of subsystem architecture fragility.")
310
+
311
+ cycle_files = [
312
+ item for item in volatile_files
313
+ if any("cycle recurrence" in reason for reason in item.get("reasons", []))
314
+ ]
315
+ if cycle_files:
316
+ top_cycle_score = sum(item["volatility_score"] for item in cycle_files[:3])
317
+ total_volatility = max(1, sum(item["volatility_score"] for item in volatile_files))
318
+ percentage = int(round((top_cycle_score / total_volatility) * 100))
319
+ insights.append(f"{len(cycle_files[:3])} files participate in {percentage}% of observed volatility from cycles.")
320
+
321
+ dependency_growth_by_subsystem = defaultdict(int)
322
+ for subsystem in fragile_subsystems:
323
+ dependency_growth_by_subsystem[subsystem["subsystem"]] += subsystem.get("dependency_growth", 0)
324
+ if dependency_growth_by_subsystem:
325
+ subsystem, growth = max(dependency_growth_by_subsystem.items(), key=lambda item: (item[1], item[0]))
326
+ if growth > 0:
327
+ insights.append(f"Dependency growth is concentrated in {subsystem}.")
328
+
329
+ if not insights:
330
+ insights.append("No concentrated architecture governance hotspot is visible in the analyzed history.")
331
+
332
+ return insights
333
+
334
+
335
+ def analyze_architecture_stability(project_path):
336
+ git_snapshots = extract_git_snapshots(project_path)
337
+ volatile_files = build_volatile_files(git_snapshots)
338
+ stable_files = build_stable_files(git_snapshots, volatile_files)
339
+ fragile_subsystems = build_fragile_subsystems(git_snapshots)
340
+ resilient_subsystems = build_resilient_subsystems(git_snapshots, fragile_subsystems)
341
+ blast_radius_ranking = build_blast_radius_ranking(git_snapshots)
342
+
343
+ if volatile_files or fragile_subsystems:
344
+ average_pressure = (
345
+ sum(item["volatility_score"] for item in volatile_files[:10])
346
+ + sum(item["fragility_score"] for item in fragile_subsystems[:5])
347
+ ) / max(1, min(10, len(volatile_files)) + min(5, len(fragile_subsystems)))
348
+ stability_score = clamp_score(100 - average_pressure)
349
+ else:
350
+ stability_score = 100
351
+
352
+ return {
353
+ "stability_score": stability_score,
354
+ "volatile_files": volatile_files,
355
+ "stable_files": stable_files,
356
+ "fragile_subsystems": fragile_subsystems,
357
+ "resilient_subsystems": resilient_subsystems,
358
+ "blast_radius_ranking": blast_radius_ranking,
359
+ "governance_insights": governance_insights(git_snapshots, fragile_subsystems, volatile_files),
360
+ "commit_count": len(git_snapshots),
361
+ }
adre/graph/__init__.py ADDED
File without changes