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
adre/core/config.py ADDED
@@ -0,0 +1,60 @@
1
+ import os
2
+
3
+ PROJECT_ROOT = os.getcwd()
4
+ SNAPSHOT_DIR = os.path.join(os.getcwd(), "snapshots")
5
+ SKIP_DIRS = {
6
+ "venv",
7
+ ".venv",
8
+ "__pycache__",
9
+ ".git",
10
+ ".idea",
11
+ ".vscode",
12
+ "node_modules",
13
+ "dist",
14
+ "build",
15
+ "coverage",
16
+ ".adre_repositories",
17
+ ".adre",
18
+ "snapshots",
19
+ ".tox",
20
+ ".mypy_cache",
21
+ ".pytest_cache",
22
+ "tests",
23
+ "test",
24
+ "__tests__",
25
+ "spec",
26
+ "specs",
27
+ "examples",
28
+ "example",
29
+ "samples",
30
+ "sample",
31
+ "demo",
32
+ "docs",
33
+ "vendor",
34
+ "generated",
35
+ "migrations",
36
+ "benchmarks",
37
+ "benchmark",
38
+ "htmlcov",
39
+ "site-packages",
40
+ ".next",
41
+ ".nuxt",
42
+ }
43
+ SEVERITY_WEIGHTS = {
44
+ "critical": 25,
45
+ "high": 15,
46
+ "medium": 8,
47
+ "low": 3,
48
+ }
49
+ MAX_FILE_BYTES = 512_000
50
+ MAX_ANALYZED_FILES = 5000
51
+ MAX_GIT_COMMITS = 20
52
+ MAX_INDIRECT_CHAINS = 200
53
+ MAX_INDIRECT_GRAPH_SIZE = 300
54
+ SOURCE_WALK_LIMIT = 400
55
+ BASELINE_SCHEMA_VERSION = 1
56
+ BASELINE_DIRNAME = ".adre"
57
+ BASELINE_FILENAME = "baseline.json"
58
+ PARSE_CACHE_FILENAME = "parse-cache.json"
59
+ PARSE_CACHE_SCHEMA_VERSION = 1
60
+ ANALYZER_VERSION = "0.9.0"
@@ -0,0 +1,361 @@
1
+ from adre.analyzers.architecture import analyze_project_architecture
2
+ from adre.core.evolution_intelligence import analyze_architecture_evolution
3
+ from adre.core.git_intelligence import detect_architecture_drift, extract_git_snapshots
4
+ from adre.core.stability_intelligence import analyze_architecture_stability
5
+
6
+
7
+ SIGNAL_WEIGHTS = {
8
+ "cycle": 35,
9
+ "hotspot": 24,
10
+ "drift": 20,
11
+ "volatility": 16,
12
+ "blast_radius": 14,
13
+ "stability": 12,
14
+ "pr_risk": 10,
15
+ "layer_violation": 10,
16
+ }
17
+
18
+
19
+ def clamp_score(value):
20
+ return max(0, min(100, int(round(value))))
21
+
22
+
23
+ def impact_level(score):
24
+ if score >= 75:
25
+ return "high"
26
+ if score >= 40:
27
+ return "medium"
28
+ return "low"
29
+
30
+
31
+ def effort_from_signals(signals, affected_files):
32
+ if "cycle" in signals or len(affected_files) >= 3:
33
+ return "high"
34
+ if "drift" in signals or "blast_radius" in signals or len(affected_files) == 2:
35
+ return "medium"
36
+ return "low"
37
+
38
+
39
+ def decision_key(decision):
40
+ files = tuple(sorted(decision.get("affected_files", [])))
41
+ return decision.get("action"), files
42
+
43
+
44
+ def normalize_decision(action, priority_score, affected_files, reason, source_signals):
45
+ source_signals = sorted(set(source_signals), key=lambda signal: (-SIGNAL_WEIGHTS.get(signal, 0), signal))
46
+ affected_files = sorted(set(file for file in affected_files if file))
47
+ score = clamp_score(priority_score + sum(SIGNAL_WEIGHTS.get(signal, 0) for signal in source_signals[:3]) // 3)
48
+ return {
49
+ "action": action,
50
+ "priority_score": score,
51
+ "impact_level": impact_level(score),
52
+ "effort_estimate": effort_from_signals(source_signals, affected_files),
53
+ "affected_files": affected_files,
54
+ "reason": reason,
55
+ "source_signals": source_signals,
56
+ }
57
+
58
+
59
+ def merge_decisions(decisions):
60
+ merged = {}
61
+ for decision in decisions:
62
+ key = decision_key(decision)
63
+ if key not in merged:
64
+ merged[key] = decision
65
+ continue
66
+ existing = merged[key]
67
+ existing["priority_score"] = max(existing["priority_score"], decision["priority_score"])
68
+ existing["impact_level"] = impact_level(existing["priority_score"])
69
+ existing["reason"] = sorted(set(existing.get("reason", []) + decision.get("reason", [])))
70
+ existing["source_signals"] = sorted(
71
+ set(existing.get("source_signals", []) + decision.get("source_signals", [])),
72
+ key=lambda signal: (-SIGNAL_WEIGHTS.get(signal, 0), signal),
73
+ )
74
+ existing["effort_estimate"] = effort_from_signals(existing["source_signals"], existing["affected_files"])
75
+ return sorted(
76
+ merged.values(),
77
+ key=lambda item: (
78
+ -item["priority_score"],
79
+ -max(SIGNAL_WEIGHTS.get(signal, 0) for signal in item.get("source_signals", ["stability"])),
80
+ item["action"],
81
+ ),
82
+ )
83
+
84
+
85
+ def decisions_from_refactors(analysis):
86
+ decisions = []
87
+ for recommendation in analysis.get("refactor_recommendations", []):
88
+ signals = []
89
+ category = recommendation.get("category")
90
+ if category == "cycle":
91
+ signals.append("cycle")
92
+ elif category == "hotspot":
93
+ signals.append("hotspot")
94
+ elif category == "layer_violation":
95
+ signals.append("layer_violation")
96
+ score = recommendation.get("priority_score", 50)
97
+ decisions.append(normalize_decision(
98
+ recommendation.get("title", "Refactor architecture boundary"),
99
+ score,
100
+ recommendation.get("affected_files", []),
101
+ [
102
+ recommendation.get("rationale", ""),
103
+ recommendation.get("recommended_action", ""),
104
+ recommendation.get("expected_benefit", ""),
105
+ ],
106
+ signals or ["stability"],
107
+ ))
108
+ return decisions
109
+
110
+
111
+ def decisions_from_file_risks(analysis):
112
+ decisions = []
113
+ for item in analysis.get("file_risk_ranking", [])[:10]:
114
+ signals = []
115
+ reasons = set(item.get("reasons", []))
116
+ if "cycle participant" in reasons:
117
+ signals.append("cycle")
118
+ if "hotspot" in reasons:
119
+ signals.append("hotspot")
120
+ if "layer rule violation" in reasons:
121
+ signals.append("layer_violation")
122
+ decisions.append(normalize_decision(
123
+ f"Stabilize architectural pressure in {item['file']}",
124
+ item.get("risk_score", 0),
125
+ [item["file"]],
126
+ [
127
+ "This file ranks highly in the current architectural risk model.",
128
+ "Reasons: " + ", ".join(item.get("reasons", [])),
129
+ ],
130
+ signals or ["stability"],
131
+ ))
132
+ return decisions
133
+
134
+
135
+ def decisions_from_evolution(evolution):
136
+ decisions = []
137
+ for subsystem in evolution.get("degrading_subsystems", [])[:5]:
138
+ decisions.append(normalize_decision(
139
+ f"Review degrading subsystem {subsystem['subsystem']}",
140
+ 55 + max(0, subsystem.get("risk_delta", 0)),
141
+ [],
142
+ [
143
+ f"{subsystem['subsystem']} is trending {subsystem.get('trend', 'degrading')}.",
144
+ f"Issue growth {subsystem.get('issue_growth', 0):+}; dependency growth {subsystem.get('dependency_growth', 0):+}.",
145
+ ],
146
+ ["drift", "stability"],
147
+ ))
148
+
149
+ for event in evolution.get("drift_events", [])[:5]:
150
+ severity_bonus = {"critical": 35, "high": 25, "medium": 12, "low": 5}.get(event.get("severity"), 5)
151
+ decisions.append(normalize_decision(
152
+ f"Investigate {event.get('event', 'architecture drift')}",
153
+ 45 + severity_bonus,
154
+ [],
155
+ [
156
+ f"Detected at commit {(event.get('commit') or 'unknown')[:12]}.",
157
+ event.get("details", ""),
158
+ ],
159
+ ["drift"],
160
+ ))
161
+ return decisions
162
+
163
+
164
+ def decisions_from_stability(stability):
165
+ decisions = []
166
+ for item in stability.get("volatile_files", [])[:8]:
167
+ signals = ["volatility", "stability"]
168
+ if any("cycle recurrence" in reason for reason in item.get("reasons", [])):
169
+ signals.append("cycle")
170
+ if any("hotspot recurrence" in reason for reason in item.get("reasons", [])):
171
+ signals.append("hotspot")
172
+ decisions.append(normalize_decision(
173
+ f"Establish ownership for {item['file']}",
174
+ item.get("volatility_score", 0),
175
+ [item["file"]],
176
+ [
177
+ "This file repeatedly appears in architectural instability signals.",
178
+ "Reasons: " + ", ".join(item.get("reasons", [])),
179
+ ],
180
+ signals,
181
+ ))
182
+
183
+ for item in stability.get("blast_radius_ranking", [])[:5]:
184
+ if item.get("blast_radius_score", 0) < 35:
185
+ continue
186
+ decisions.append(normalize_decision(
187
+ f"Reduce blast radius of {item['file']}",
188
+ item.get("blast_radius_score", 0),
189
+ [item["file"]],
190
+ [
191
+ f"{item['file']} has {item.get('inbound_dependencies', 0)} inbound dependencies "
192
+ f"and {item.get('transitive_dependents', 0)} transitive dependents.",
193
+ ],
194
+ ["blast_radius"] + (["hotspot"] if item.get("hotspot") else []),
195
+ ))
196
+
197
+ for subsystem in stability.get("fragile_subsystems", [])[:5]:
198
+ decisions.append(normalize_decision(
199
+ f"Create governance checkpoint for {subsystem['subsystem']}",
200
+ subsystem.get("fragility_score", 0),
201
+ [],
202
+ [
203
+ f"{subsystem['subsystem']} has fragility score {subsystem.get('fragility_score', 0)}.",
204
+ f"Trend: {subsystem.get('trend', 'watch')}.",
205
+ ],
206
+ ["stability", "volatility"],
207
+ ))
208
+ return decisions
209
+
210
+
211
+ def decisions_from_drift(drift):
212
+ decisions = []
213
+ for point in drift.get("drift_points", [])[:5]:
214
+ severity_bonus = {"critical": 35, "high": 25, "medium": 12, "low": 5}.get(point.get("severity"), 5)
215
+ decisions.append(normalize_decision(
216
+ f"Audit drift point {(point.get('commit') or 'unknown')[:12]}",
217
+ 45 + severity_bonus,
218
+ [],
219
+ [point.get("reason", "Architecture drift was detected in git history.")],
220
+ ["drift"],
221
+ ))
222
+ return decisions
223
+
224
+
225
+ def decisions_from_pr_risk(analysis):
226
+ decisions = []
227
+ if analysis.get("cycles"):
228
+ decisions.append(normalize_decision(
229
+ "Fix cycle before enforcing PR architecture gate",
230
+ 82,
231
+ sorted({file for cycle in analysis.get("cycles", []) for file in cycle if file}),
232
+ [
233
+ "Current cycles would be treated as critical risk if introduced in a pull request.",
234
+ "Resolving them reduces future PR gate noise and merge risk.",
235
+ ],
236
+ ["cycle", "pr_risk"],
237
+ ))
238
+ high_issues = [issue for issue in analysis.get("issues", []) if issue.get("severity") in {"critical", "high"}]
239
+ if high_issues:
240
+ decisions.append(normalize_decision(
241
+ "Reduce high-severity layer violations before tightening PR checks",
242
+ 65,
243
+ [issue.get("file") for issue in high_issues],
244
+ [
245
+ f"{len(high_issues)} critical/high architecture issue(s) exist in the current baseline.",
246
+ "Lowering baseline violations makes PR enforcement more actionable.",
247
+ ],
248
+ ["layer_violation", "pr_risk"],
249
+ ))
250
+ return decisions
251
+
252
+
253
+ def architecture_executive_summary_from_data(analysis, evolution, stability, decisions):
254
+ systemic_risks = []
255
+ if analysis.get("cycles"):
256
+ systemic_risks.append(f"{len(analysis['cycles'])} dependency cycle(s) are present.")
257
+ if analysis.get("hotspot_files"):
258
+ systemic_risks.append(f"{len(analysis['hotspot_files'])} hotspot file(s) concentrate dependency pressure.")
259
+ if stability.get("volatile_files"):
260
+ top = stability["volatile_files"][0]
261
+ systemic_risks.append(f"{top['file']} is the most volatile architecture file.")
262
+ if evolution.get("drift_events"):
263
+ systemic_risks.append(f"{len(evolution['drift_events'])} major architecture drift event(s) were detected.")
264
+
265
+ if not systemic_risks:
266
+ systemic_risks.append("No major systemic architecture risk is currently visible.")
267
+
268
+ if stability.get("fragile_subsystems"):
269
+ main_weakness = stability["fragile_subsystems"][0]["subsystem"]
270
+ elif evolution.get("degrading_subsystems"):
271
+ main_weakness = evolution["degrading_subsystems"][0]["subsystem"]
272
+ elif analysis.get("file_risk_ranking"):
273
+ main_weakness = analysis["file_risk_ranking"][0]["file"]
274
+ else:
275
+ main_weakness = "No concentrated weakness detected"
276
+
277
+ return {
278
+ "current_architecture_health": {
279
+ "score": analysis.get("score", 0),
280
+ "architecture_type": analysis.get("architecture_type", "unknown"),
281
+ "stability_score": stability.get("stability_score", 0),
282
+ },
283
+ "top_3_systemic_risks": systemic_risks[:3],
284
+ "top_3_recommended_actions": [decision["action"] for decision in decisions[:3]],
285
+ "main_structural_weakness": main_weakness,
286
+ "overall_trajectory": evolution.get("trend", "stable"),
287
+ }
288
+
289
+
290
+ def generate_architecture_decisions(project_path):
291
+ analysis = analyze_project_architecture(project_path)
292
+ git_snapshots = []
293
+ evolution = {
294
+ "trend": "stable",
295
+ "drift_events": [],
296
+ "degrading_subsystems": [],
297
+ }
298
+ drift = {"drift_points": []}
299
+
300
+ try:
301
+ git_snapshots = extract_git_snapshots(project_path)
302
+ evolution = analyze_architecture_evolution(git_snapshots)
303
+ drift = detect_architecture_drift(git_snapshots)
304
+ except Exception as exc:
305
+ evolution = {
306
+ "trend": "stable",
307
+ "drift_events": [],
308
+ "degrading_subsystems": [],
309
+ "unavailable_reason": str(exc),
310
+ }
311
+ drift = {"drift_points": []}
312
+
313
+ try:
314
+ stability = analyze_architecture_stability(project_path)
315
+ except Exception as exc:
316
+ stability = {
317
+ "stability_score": 100,
318
+ "volatile_files": [],
319
+ "stable_files": [],
320
+ "fragile_subsystems": [],
321
+ "resilient_subsystems": [],
322
+ "blast_radius_ranking": [],
323
+ "governance_insights": [f"Stability history unavailable: {exc}"],
324
+ "commit_count": len(git_snapshots),
325
+ }
326
+
327
+ decisions = []
328
+ decisions.extend(decisions_from_refactors(analysis))
329
+ decisions.extend(decisions_from_file_risks(analysis))
330
+ decisions.extend(decisions_from_evolution(evolution))
331
+ decisions.extend(decisions_from_stability(stability))
332
+ decisions.extend(decisions_from_drift(drift))
333
+ decisions.extend(decisions_from_pr_risk(analysis))
334
+ decisions = merge_decisions(decisions)
335
+ executive_summary = architecture_executive_summary_from_data(
336
+ analysis,
337
+ evolution,
338
+ stability,
339
+ decisions,
340
+ )
341
+
342
+ return {
343
+ "project_path": project_path,
344
+ "decisions": decisions,
345
+ "executive_summary": executive_summary,
346
+ "impact_overview": {
347
+ "high": sum(1 for decision in decisions if decision["impact_level"] == "high"),
348
+ "medium": sum(1 for decision in decisions if decision["impact_level"] == "medium"),
349
+ "low": sum(1 for decision in decisions if decision["impact_level"] == "low"),
350
+ },
351
+ "key_risks": executive_summary["top_3_systemic_risks"],
352
+ "source_status": {
353
+ "git_snapshots": len(git_snapshots),
354
+ "stability_score": stability.get("stability_score", 0),
355
+ "trajectory": evolution.get("trend", "stable"),
356
+ },
357
+ }
358
+
359
+
360
+ def architecture_executive_summary(project_path):
361
+ return generate_architecture_decisions(project_path)["executive_summary"]