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.
- adre/__init__.py +5 -0
- adre/analyzers/__init__.py +1 -0
- adre/analyzers/architecture.py +253 -0
- adre/analyzers/findings.py +457 -0
- adre/analyzers/inference.py +163 -0
- adre/cli.py +923 -0
- adre/core/__init__.py +1 -0
- adre/core/accepted.py +225 -0
- adre/core/adaptive.py +221 -0
- adre/core/baseline.py +1165 -0
- adre/core/config.py +60 -0
- adre/core/decision_engine.py +361 -0
- adre/core/declared.py +313 -0
- adre/core/evolution_intelligence.py +390 -0
- adre/core/explainer.py +413 -0
- adre/core/git_intelligence.py +392 -0
- adre/core/github_check.py +212 -0
- adre/core/incremental.py +288 -0
- adre/core/layers.py +306 -0
- adre/core/pr_intelligence.py +261 -0
- adre/core/pr_review.py +454 -0
- adre/core/prioritization.py +196 -0
- adre/core/project.py +41 -0
- adre/core/refactor_intelligence.py +201 -0
- adre/core/repositories.py +312 -0
- adre/core/review.py +96 -0
- adre/core/rules_shared.py +75 -0
- adre/core/sarif.py +141 -0
- adre/core/scope.py +141 -0
- adre/core/snapshots.py +242 -0
- adre/core/stability_intelligence.py +361 -0
- adre/graph/__init__.py +0 -0
- adre/graph/dependencies.py +379 -0
- adre/parsers/__init__.py +87 -0
- adre/parsers/go.py +140 -0
- adre/parsers/javascript.py +364 -0
- adre/parsers/jvm.py +127 -0
- adre/parsers/python.py +153 -0
- adre/reports/__init__.py +1 -0
- adre/reports/architecture.py +349 -0
- adre/rules.py +12 -0
- adre/web.py +3731 -0
- adre_cli-0.1.0.dist-info/METADATA +343 -0
- adre_cli-0.1.0.dist-info/RECORD +48 -0
- adre_cli-0.1.0.dist-info/WHEEL +5 -0
- adre_cli-0.1.0.dist-info/entry_points.txt +2 -0
- adre_cli-0.1.0.dist-info/licenses/LICENSE +202 -0
- adre_cli-0.1.0.dist-info/top_level.txt +1 -0
adre/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
from collections import defaultdict
|
|
2
|
+
|
|
3
|
+
from adre.analyzers.findings import findings_to_issues, generate_findings
|
|
4
|
+
from adre.analyzers.inference import infer_architecture_model
|
|
5
|
+
from adre.core.baseline import architecture_type_from_baseline, build_architecture_baseline
|
|
6
|
+
from adre.core.config import ANALYZER_VERSION, PROJECT_ROOT, SEVERITY_WEIGHTS, SKIP_DIRS
|
|
7
|
+
from adre.core.incremental import finalize_incremental_index
|
|
8
|
+
from adre.core.layers import get_layer, refine_relationship_clusters
|
|
9
|
+
from adre.core.prioritization import build_file_risk_ranking, rank_architecture_issues
|
|
10
|
+
from adre.core.refactor_intelligence import generate_refactor_recommendations
|
|
11
|
+
from adre.core.scope import build_analysis_scope
|
|
12
|
+
from adre.graph.dependencies import (
|
|
13
|
+
build_graph,
|
|
14
|
+
build_project_index,
|
|
15
|
+
detect_cycle_groups,
|
|
16
|
+
detect_cycles,
|
|
17
|
+
detect_indirect_dependencies,
|
|
18
|
+
dependency_graph_edges,
|
|
19
|
+
find_hotspot_files,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def count_severities(issues):
|
|
24
|
+
counts = {"critical": 0, "high": 0, "medium": 0, "low": 0}
|
|
25
|
+
for issue in issues:
|
|
26
|
+
counts[issue["severity"]] = counts.get(issue["severity"], 0) + 1
|
|
27
|
+
return counts
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def calculate_risk_scores(issues, cycles, indirect_dependencies, hotspot_files, dependency_graph):
|
|
31
|
+
file_count = max(1, len(dependency_graph))
|
|
32
|
+
edge_count = sum(len(data.get("imports", [])) for data in dependency_graph.values())
|
|
33
|
+
severity_counts = count_severities(issues)
|
|
34
|
+
coupling_risk_score = min(100, int((edge_count / file_count) * 15) + min(len(indirect_dependencies) * 4, 40))
|
|
35
|
+
cycle_risk_score = min(100, len(cycles) * 35)
|
|
36
|
+
layer_violation_score = min(
|
|
37
|
+
100,
|
|
38
|
+
severity_counts["critical"] * 30
|
|
39
|
+
+ severity_counts["high"] * 20
|
|
40
|
+
+ severity_counts["medium"] * 10
|
|
41
|
+
+ severity_counts["low"] * 4
|
|
42
|
+
)
|
|
43
|
+
hotspot_pressure_score = min(100, sum(item.get("dependency_count", 0) for item in hotspot_files) * 8)
|
|
44
|
+
weighted_risk_score = int(
|
|
45
|
+
coupling_risk_score * 0.25
|
|
46
|
+
+ cycle_risk_score * 0.30
|
|
47
|
+
+ layer_violation_score * 0.30
|
|
48
|
+
+ hotspot_pressure_score * 0.15
|
|
49
|
+
)
|
|
50
|
+
return {
|
|
51
|
+
"coupling_risk_score": coupling_risk_score,
|
|
52
|
+
"cycle_risk_score": cycle_risk_score,
|
|
53
|
+
"layer_violation_score": layer_violation_score,
|
|
54
|
+
"hotspot_pressure_score": hotspot_pressure_score,
|
|
55
|
+
"weighted_risk_score": weighted_risk_score
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def calculate_architecture_score(issues, cycles, indirect_dependencies):
|
|
60
|
+
legacy_score = 100
|
|
61
|
+
for issue in issues:
|
|
62
|
+
legacy_score -= SEVERITY_WEIGHTS.get(issue["severity"], 5)
|
|
63
|
+
legacy_score -= len(cycles) * 20
|
|
64
|
+
legacy_score -= min(len(indirect_dependencies), 10) * 2
|
|
65
|
+
return max(0, legacy_score)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def calculate_weighted_architecture_score(risk_scores):
|
|
69
|
+
return max(0, 100 - risk_scores["weighted_risk_score"])
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def confidence_penalty(confidence):
|
|
73
|
+
if confidence >= 0.6:
|
|
74
|
+
return 0
|
|
75
|
+
if confidence >= 0.45:
|
|
76
|
+
return 10
|
|
77
|
+
if confidence >= 0.3:
|
|
78
|
+
return 20
|
|
79
|
+
return 30
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _subgraph(resolved_graph, analyzed_files):
|
|
83
|
+
analyzed = set(analyzed_files)
|
|
84
|
+
return {
|
|
85
|
+
file_path: set(target for target in targets if target in analyzed)
|
|
86
|
+
for file_path, targets in resolved_graph.items()
|
|
87
|
+
if file_path in analyzed
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def analyze_project_architecture(
|
|
92
|
+
project_root=PROJECT_ROOT,
|
|
93
|
+
selected_paths=None,
|
|
94
|
+
expand_related=True,
|
|
95
|
+
persist_cache=True,
|
|
96
|
+
reuse_cache=True,
|
|
97
|
+
):
|
|
98
|
+
dependency_graph, index_meta = build_project_index(
|
|
99
|
+
project_root,
|
|
100
|
+
persist_cache=persist_cache,
|
|
101
|
+
reuse_cache=reuse_cache,
|
|
102
|
+
)
|
|
103
|
+
full_resolved = build_graph(dependency_graph)
|
|
104
|
+
refine_relationship_clusters(dependency_graph, full_resolved)
|
|
105
|
+
incremental = finalize_incremental_index(
|
|
106
|
+
project_root,
|
|
107
|
+
dependency_graph,
|
|
108
|
+
full_resolved,
|
|
109
|
+
index_meta.get("incremental") or {},
|
|
110
|
+
persist_cache=persist_cache and index_meta.get("persist_cache", True),
|
|
111
|
+
)
|
|
112
|
+
inferred = infer_architecture_model(dependency_graph, full_resolved)
|
|
113
|
+
scope = build_analysis_scope(
|
|
114
|
+
project_root,
|
|
115
|
+
dependency_graph,
|
|
116
|
+
full_resolved,
|
|
117
|
+
selected_paths=selected_paths,
|
|
118
|
+
expand_related=expand_related,
|
|
119
|
+
truncated=index_meta.get("truncated", False),
|
|
120
|
+
unsupported_files=index_meta.get("unsupported_files", 0),
|
|
121
|
+
)
|
|
122
|
+
scope["excluded_directories"] = sorted(SKIP_DIRS)
|
|
123
|
+
scope["incremental"] = incremental
|
|
124
|
+
|
|
125
|
+
analyzed_files = scope["analyzed_files"]
|
|
126
|
+
analyzed_graph = {path: dependency_graph[path] for path in analyzed_files if path in dependency_graph}
|
|
127
|
+
resolved_graph = _subgraph(full_resolved, analyzed_files)
|
|
128
|
+
# Cycles only count imports that execute at module load time.
|
|
129
|
+
runtime_graph = _subgraph(build_graph(dependency_graph, runtime_only=True), analyzed_files)
|
|
130
|
+
cycle_groups = detect_cycle_groups(runtime_graph)
|
|
131
|
+
cycles = detect_cycles(runtime_graph)
|
|
132
|
+
current_architecture = build_architecture_baseline(
|
|
133
|
+
project_root,
|
|
134
|
+
scope,
|
|
135
|
+
analyzed_graph,
|
|
136
|
+
resolved_graph,
|
|
137
|
+
inferred=inferred,
|
|
138
|
+
cycles=cycles,
|
|
139
|
+
cycle_groups=cycle_groups,
|
|
140
|
+
runtime_graph=runtime_graph,
|
|
141
|
+
)
|
|
142
|
+
inferred["enough_structure"] = current_architecture.get("enough_structure", False)
|
|
143
|
+
inferred["established_pattern"] = current_architecture.get("summary_path") or ""
|
|
144
|
+
inferred["confidence"] = current_architecture.get("confidence") or 0
|
|
145
|
+
architecture_type = architecture_type_from_baseline(current_architecture)
|
|
146
|
+
detected_layers = [
|
|
147
|
+
layer["name"]
|
|
148
|
+
for layer in current_architecture.get("layers") or []
|
|
149
|
+
if layer.get("role") != "unknown"
|
|
150
|
+
]
|
|
151
|
+
indirect_dependencies = detect_indirect_dependencies(resolved_graph)
|
|
152
|
+
hotspot_files = find_hotspot_files(resolved_graph)
|
|
153
|
+
for hotspot in hotspot_files:
|
|
154
|
+
hotspot["layer"] = analyzed_graph.get(hotspot["file"], {}).get(
|
|
155
|
+
"layer",
|
|
156
|
+
get_layer(hotspot["file"]),
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
findings = generate_findings(
|
|
160
|
+
analyzed_graph,
|
|
161
|
+
resolved_graph,
|
|
162
|
+
inferred,
|
|
163
|
+
cycles,
|
|
164
|
+
analyzed_files=analyzed_files,
|
|
165
|
+
baseline=current_architecture,
|
|
166
|
+
)
|
|
167
|
+
issues = findings_to_issues(findings)
|
|
168
|
+
severity_counts = count_severities(issues)
|
|
169
|
+
risk_scores = calculate_risk_scores(issues, cycles, indirect_dependencies, hotspot_files, analyzed_graph)
|
|
170
|
+
architecture_confidence = float(current_architecture.get("confidence") or 0)
|
|
171
|
+
penalty = confidence_penalty(architecture_confidence)
|
|
172
|
+
base_score = calculate_weighted_architecture_score(risk_scores)
|
|
173
|
+
score = max(0, base_score - penalty)
|
|
174
|
+
analysis = {
|
|
175
|
+
"project_root": project_root,
|
|
176
|
+
"scope": scope,
|
|
177
|
+
"incremental": incremental,
|
|
178
|
+
"architecture_type": architecture_type,
|
|
179
|
+
"architecture_confidence": architecture_confidence,
|
|
180
|
+
"detected_layers": detected_layers,
|
|
181
|
+
"inferred_architecture": inferred,
|
|
182
|
+
"architecture": current_architecture,
|
|
183
|
+
"established_pattern": current_architecture.get("summary_path") or "",
|
|
184
|
+
"architecture_rules": {
|
|
185
|
+
"architecture_type": architecture_type,
|
|
186
|
+
"layer_rules": {
|
|
187
|
+
item["source"]: [item["target"]]
|
|
188
|
+
for item in current_architecture.get("directions") or []
|
|
189
|
+
if item.get("established")
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
"low_confidence": architecture_confidence < 0.6,
|
|
193
|
+
"confidence_penalty": penalty,
|
|
194
|
+
"dependency_graph": analyzed_graph,
|
|
195
|
+
"full_dependency_graph": dependency_graph,
|
|
196
|
+
"resolved_graph": {file: sorted(targets) for file, targets in resolved_graph.items()},
|
|
197
|
+
"findings": findings,
|
|
198
|
+
"issues": issues,
|
|
199
|
+
"cycles": cycles,
|
|
200
|
+
"cycle_groups": cycle_groups,
|
|
201
|
+
"runtime_graph": {file: sorted(targets) for file, targets in runtime_graph.items()},
|
|
202
|
+
"indirect_dependencies": indirect_dependencies,
|
|
203
|
+
"hotspot_files": hotspot_files,
|
|
204
|
+
"score": score,
|
|
205
|
+
"base_score": base_score,
|
|
206
|
+
"risk_scores": risk_scores,
|
|
207
|
+
"legacy_score": calculate_architecture_score(issues, cycles, indirect_dependencies),
|
|
208
|
+
"severity_counts": severity_counts,
|
|
209
|
+
"analyzer_version": ANALYZER_VERSION,
|
|
210
|
+
}
|
|
211
|
+
analysis["priority_issues"] = rank_architecture_issues(analysis)
|
|
212
|
+
analysis["file_risk_ranking"] = build_file_risk_ranking(analysis)
|
|
213
|
+
analysis["refactor_recommendations"] = generate_refactor_recommendations(analysis)
|
|
214
|
+
return analysis
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def format_dependency_edges(edges):
|
|
218
|
+
return [{"source": source, "target": target} for source, target in sorted(edges)]
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def count_inbound_dependencies(dependency_graph):
|
|
222
|
+
inbound_counts = defaultdict(int)
|
|
223
|
+
for source, target in dependency_graph_edges(dependency_graph):
|
|
224
|
+
inbound_counts[target] += 1
|
|
225
|
+
return inbound_counts
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def count_outbound_dependencies(dependency_graph):
|
|
229
|
+
outbound_counts = defaultdict(int)
|
|
230
|
+
for source, target in dependency_graph_edges(dependency_graph):
|
|
231
|
+
outbound_counts[source] += 1
|
|
232
|
+
return outbound_counts
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def calculate_dependency_growth_per_file(before_graph, after_graph):
|
|
236
|
+
before_inbound = count_inbound_dependencies(before_graph)
|
|
237
|
+
after_inbound = count_inbound_dependencies(after_graph)
|
|
238
|
+
before_outbound = count_outbound_dependencies(before_graph)
|
|
239
|
+
after_outbound = count_outbound_dependencies(after_graph)
|
|
240
|
+
files = sorted(set(before_graph.keys()) | set(after_graph.keys()) | set(before_inbound.keys()) | set(after_inbound.keys()))
|
|
241
|
+
growth = []
|
|
242
|
+
for file in files:
|
|
243
|
+
inbound_delta = after_inbound.get(file, 0) - before_inbound.get(file, 0)
|
|
244
|
+
outbound_delta = after_outbound.get(file, 0) - before_outbound.get(file, 0)
|
|
245
|
+
if inbound_delta == 0 and outbound_delta == 0:
|
|
246
|
+
continue
|
|
247
|
+
growth.append({
|
|
248
|
+
"file": file,
|
|
249
|
+
"inbound_dependency_delta": inbound_delta,
|
|
250
|
+
"outbound_dependency_delta": outbound_delta,
|
|
251
|
+
"net_dependency_delta": inbound_delta + outbound_delta
|
|
252
|
+
})
|
|
253
|
+
return sorted(growth, key=lambda item: (-abs(item["net_dependency_delta"]), item["file"]))
|