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/cli.py
ADDED
|
@@ -0,0 +1,923 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
from contextlib import redirect_stdout
|
|
6
|
+
|
|
7
|
+
from adre.analyzers.architecture import analyze_project_architecture
|
|
8
|
+
from adre import __version__
|
|
9
|
+
from adre.core.config import ANALYZER_VERSION
|
|
10
|
+
from adre.core.baseline import (
|
|
11
|
+
save_architecture_baseline,
|
|
12
|
+
)
|
|
13
|
+
from adre.core.decision_engine import generate_architecture_decisions
|
|
14
|
+
from adre.core.evolution_intelligence import analyze_architecture_evolution
|
|
15
|
+
from adre.core.explainer import attach_explanation_context_to_decisions, generate_architecture_explanation
|
|
16
|
+
from adre.core.git_intelligence import (
|
|
17
|
+
blame_architecture_file,
|
|
18
|
+
build_architecture_timeline,
|
|
19
|
+
build_evolution_report,
|
|
20
|
+
detect_architecture_drift,
|
|
21
|
+
extract_git_snapshots,
|
|
22
|
+
)
|
|
23
|
+
from adre.core.review import review_working_tree
|
|
24
|
+
from adre.core.github_check import format_github_check, write_github_output, write_step_outputs
|
|
25
|
+
from adre.core.sarif import write_sarif
|
|
26
|
+
from adre.core.pr_review import exit_code_for, review_pull_request
|
|
27
|
+
from adre.core.snapshots import compare_snapshot_data, load_snapshot_file, snapshot_from_analysis
|
|
28
|
+
from adre.core.stability_intelligence import analyze_architecture_stability
|
|
29
|
+
from adre.reports.architecture import build_architecture_report
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def print_header(title):
|
|
33
|
+
print(title)
|
|
34
|
+
print("=" * len(title))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def print_issue(issue):
|
|
38
|
+
title = issue.get("title") or "{0} -> {1}".format(issue.get("file"), issue.get("imported"))
|
|
39
|
+
confidence = issue.get("confidence")
|
|
40
|
+
kind = issue.get("kind")
|
|
41
|
+
extras = []
|
|
42
|
+
if kind:
|
|
43
|
+
extras.append(kind)
|
|
44
|
+
if confidence is not None:
|
|
45
|
+
extras.append("{0:.0%} confidence".format(confidence))
|
|
46
|
+
suffix = " ({0})".format(", ".join(extras)) if extras else ""
|
|
47
|
+
print("- [{0}] {1}{2}".format(issue.get("severity", "unknown"), title, suffix))
|
|
48
|
+
problem = issue.get("problem") or issue.get("explanation")
|
|
49
|
+
if problem:
|
|
50
|
+
print(" Problem: {0}".format(problem))
|
|
51
|
+
if issue.get("changed"):
|
|
52
|
+
print(" Changed: {0}".format(issue["changed"]))
|
|
53
|
+
established = issue.get("established") or issue.get("established_pattern")
|
|
54
|
+
if established:
|
|
55
|
+
print(" Established: {0}".format(established))
|
|
56
|
+
if issue.get("reason"):
|
|
57
|
+
print(" Reason: {0}".format(issue["reason"]))
|
|
58
|
+
evidence = issue.get("evidence") or []
|
|
59
|
+
if evidence:
|
|
60
|
+
print(" Evidence: {0}".format("; ".join(evidence)))
|
|
61
|
+
affected = issue.get("affected_files") or []
|
|
62
|
+
if affected:
|
|
63
|
+
print(" Affected files: {0}".format(", ".join(affected[:8])))
|
|
64
|
+
if issue.get("why_it_matters") and issue.get("why_it_matters") != issue.get("reason"):
|
|
65
|
+
print(" Why this matters: {0}".format(issue["why_it_matters"]))
|
|
66
|
+
fix = issue.get("fix")
|
|
67
|
+
if fix:
|
|
68
|
+
print(" Fix: {0}".format(fix))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def print_architecture(baseline):
|
|
72
|
+
if not baseline:
|
|
73
|
+
return
|
|
74
|
+
print("\nArchitecture:")
|
|
75
|
+
print("Classification: {0}".format(baseline.get("classification", "insufficient")))
|
|
76
|
+
print("Confidence: {0:.2f}".format(float(baseline.get("confidence") or 0)))
|
|
77
|
+
if baseline.get("summary_path"):
|
|
78
|
+
print("Dependency direction: {0}".format(baseline["summary_path"]))
|
|
79
|
+
if not baseline.get("enough_structure"):
|
|
80
|
+
for note in baseline.get("notes") or []:
|
|
81
|
+
print("Note: {0}".format(note))
|
|
82
|
+
return
|
|
83
|
+
|
|
84
|
+
layers = baseline.get("layers") or []
|
|
85
|
+
known = [layer for layer in layers if layer.get("role") != "unknown"]
|
|
86
|
+
if known:
|
|
87
|
+
print("\nLayers:")
|
|
88
|
+
for layer in known:
|
|
89
|
+
print(
|
|
90
|
+
"- {0} ({1}, {2}, {3:.0%} confidence)".format(
|
|
91
|
+
layer["name"],
|
|
92
|
+
layer.get("role"),
|
|
93
|
+
layer.get("classification"),
|
|
94
|
+
float(layer.get("confidence") or 0),
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
for detail in (layer.get("evidence") or [])[:2]:
|
|
98
|
+
text = detail.get("detail") if isinstance(detail, dict) else detail
|
|
99
|
+
print(" Evidence: {0}".format(text))
|
|
100
|
+
|
|
101
|
+
directions = [item for item in baseline.get("directions") or [] if item.get("count")]
|
|
102
|
+
if directions:
|
|
103
|
+
print("\nObserved directions:")
|
|
104
|
+
for item in directions[:12]:
|
|
105
|
+
mark = "established" if item.get("established") else "observed"
|
|
106
|
+
print(
|
|
107
|
+
"- {0} -> {1} ({2}, {3} edge(s))".format(
|
|
108
|
+
item["source"], item["target"], mark, item.get("count", 0)
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
patterns = baseline.get("patterns") or []
|
|
113
|
+
if patterns:
|
|
114
|
+
print("\nPatterns:")
|
|
115
|
+
for pattern in patterns:
|
|
116
|
+
print(
|
|
117
|
+
"- {0} ({1}, {2:.0%} confidence)".format(
|
|
118
|
+
pattern.get("name"),
|
|
119
|
+
pattern.get("classification"),
|
|
120
|
+
float(pattern.get("confidence") or 0),
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
for detail in (pattern.get("evidence") or [])[:3]:
|
|
124
|
+
text = detail.get("detail") if isinstance(detail, dict) else detail
|
|
125
|
+
print(" Evidence: {0}".format(text))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def print_review(comparison):
|
|
129
|
+
print_header("Architecture Review")
|
|
130
|
+
print("Comparing current analysis against the saved baseline.")
|
|
131
|
+
print(comparison.get("summary") or "No comparison summary.")
|
|
132
|
+
if comparison.get("analyzer_version_mismatch"):
|
|
133
|
+
print(
|
|
134
|
+
"Note: baseline analyzer {0} differs from current {1}.".format(
|
|
135
|
+
comparison.get("baseline_analyzer_version"),
|
|
136
|
+
comparison.get("current_analyzer_version"),
|
|
137
|
+
)
|
|
138
|
+
)
|
|
139
|
+
if comparison.get("baseline_summary_path"):
|
|
140
|
+
print("Established: {0}".format(comparison["baseline_summary_path"]))
|
|
141
|
+
if comparison.get("current_summary_path"):
|
|
142
|
+
print("Current: {0}".format(comparison["current_summary_path"]))
|
|
143
|
+
print(
|
|
144
|
+
"Changes: +{0} dependencies, -{1} dependencies, +{2} cycles, -{3} cycles".format(
|
|
145
|
+
len(comparison.get("added_dependencies") or []),
|
|
146
|
+
len(comparison.get("removed_dependencies") or []),
|
|
147
|
+
len(comparison.get("new_cycles") or []),
|
|
148
|
+
len(comparison.get("resolved_cycles") or []),
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
incremental = comparison.get("incremental") or {}
|
|
152
|
+
if incremental:
|
|
153
|
+
print_incremental(incremental)
|
|
154
|
+
accepted = comparison.get("accepted_drift") or []
|
|
155
|
+
if accepted:
|
|
156
|
+
print("\nAccepted exceptions ({0}):".format(len(accepted)))
|
|
157
|
+
for item in accepted:
|
|
158
|
+
print("- {0} ({1}): {2}".format(
|
|
159
|
+
item.get("changed") or item.get("file"),
|
|
160
|
+
item.get("issue_type"),
|
|
161
|
+
(item.get("accepted_by") or {}).get("reason") or "",
|
|
162
|
+
))
|
|
163
|
+
stale = comparison.get("stale_accepted") or []
|
|
164
|
+
if stale:
|
|
165
|
+
print("\nStale accepted exceptions ({0}) no longer match any dependency; remove them:".format(len(stale)))
|
|
166
|
+
for rule in stale:
|
|
167
|
+
print("- entry {0}: {1} -> {2} ({3})".format(rule["index"], rule["from"], rule["to"], rule["reason"]))
|
|
168
|
+
drift = comparison.get("drift") or []
|
|
169
|
+
if not drift:
|
|
170
|
+
print("\nNo architectural drift findings.")
|
|
171
|
+
return
|
|
172
|
+
print("\nDrift findings:")
|
|
173
|
+
for item in drift:
|
|
174
|
+
print_issue(item)
|
|
175
|
+
print("\nTo accept an intentional crossing, add an entry with a reason to .adre/accepted.json.")
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def print_incremental(incremental):
|
|
179
|
+
if not incremental:
|
|
180
|
+
return
|
|
181
|
+
print("\nIncremental analysis:")
|
|
182
|
+
print("Discovered: {0}".format(incremental.get("discovered", 0)))
|
|
183
|
+
print("Unchanged: {0}".format(incremental.get("reused", 0)))
|
|
184
|
+
print("Changed: {0}".format(incremental.get("changed", 0)))
|
|
185
|
+
print("Added: {0}".format(incremental.get("added", 0)))
|
|
186
|
+
print("Deleted: {0}".format(incremental.get("deleted", 0)))
|
|
187
|
+
print("Parsed: {0}".format(incremental.get("parsed", 0)))
|
|
188
|
+
print("Reused: {0}".format(incremental.get("reused", 0)))
|
|
189
|
+
if incremental.get("invalidated"):
|
|
190
|
+
print("Reevaluated relationships: {0}".format(incremental.get("invalidated", 0)))
|
|
191
|
+
if incremental.get("cache_used"):
|
|
192
|
+
print("Parse cache: used")
|
|
193
|
+
else:
|
|
194
|
+
print("Parse cache: {0}".format(incremental.get("cache_reason") or "not used"))
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def print_scope(scope):
|
|
198
|
+
if not scope:
|
|
199
|
+
return
|
|
200
|
+
print("\nAnalysis scope:")
|
|
201
|
+
print("Mode: {0}".format(scope.get("selection_mode", "repository")))
|
|
202
|
+
print("Indexed files: {0}".format(scope.get("indexed_file_count", 0)))
|
|
203
|
+
print("Analyzed files: {0}".format(scope.get("analyzed_file_count", 0)))
|
|
204
|
+
languages = scope.get("languages") or {}
|
|
205
|
+
if languages:
|
|
206
|
+
print("Languages: {0}".format(", ".join("{0} {1}".format(name, count) for name, count in sorted(languages.items()))))
|
|
207
|
+
if scope.get("selected_files"):
|
|
208
|
+
print("Selected: {0}".format(", ".join(scope["selected_files"][:20])))
|
|
209
|
+
if scope.get("expanded_files"):
|
|
210
|
+
print("Expanded from dependencies: {0}".format(", ".join(scope["expanded_files"][:20])))
|
|
211
|
+
if scope.get("missing_paths"):
|
|
212
|
+
print("Missing selection: {0}".format(", ".join(scope["missing_paths"])))
|
|
213
|
+
if scope.get("truncated"):
|
|
214
|
+
print("Note: file indexing was truncated at the analyzer limit.")
|
|
215
|
+
if scope.get("unsupported_files"):
|
|
216
|
+
print("Unsupported source files skipped: {0}".format(scope["unsupported_files"]))
|
|
217
|
+
if scope.get("parse_errors"):
|
|
218
|
+
print("Parse errors: {0}".format(scope["parse_errors"]))
|
|
219
|
+
excluded = scope.get("excluded_directories") or []
|
|
220
|
+
if excluded:
|
|
221
|
+
print("Excluded: {0}".format(", ".join(excluded[:12])))
|
|
222
|
+
print_incremental(scope.get("incremental"))
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def print_analysis(analysis):
|
|
226
|
+
print_header("Architecture Analysis")
|
|
227
|
+
print("Current analysis of the selected code. This command does not update the saved baseline.")
|
|
228
|
+
print(f"Project: {analysis['project_root']}")
|
|
229
|
+
print(f"Architecture Type: {analysis.get('architecture_type', 'unknown')}")
|
|
230
|
+
print(f"Confidence: {analysis.get('architecture_confidence', 0):.2f}")
|
|
231
|
+
if analysis.get("established_pattern"):
|
|
232
|
+
print(f"Detected architecture: {analysis['established_pattern']}")
|
|
233
|
+
if analysis.get("low_confidence"):
|
|
234
|
+
print(f"Confidence Status: low confidence (-{analysis.get('confidence_penalty', 0)} score penalty)")
|
|
235
|
+
print(f"Architecture score: {analysis['score']}/100")
|
|
236
|
+
print(
|
|
237
|
+
"Issues: "
|
|
238
|
+
f"{len(analysis['issues'])} "
|
|
239
|
+
f"(critical {analysis['severity_counts']['critical']}, "
|
|
240
|
+
f"high {analysis['severity_counts']['high']}, "
|
|
241
|
+
f"medium {analysis['severity_counts']['medium']}, "
|
|
242
|
+
f"low {analysis['severity_counts']['low']})"
|
|
243
|
+
)
|
|
244
|
+
print(f"Cycles: {len(analysis['cycles'])}")
|
|
245
|
+
print(f"Indirect dependency chains: {len(analysis['indirect_dependencies'])}")
|
|
246
|
+
print(f"Hotspots: {len(analysis['hotspot_files'])}")
|
|
247
|
+
print_scope(analysis.get("scope"))
|
|
248
|
+
print_architecture(analysis.get("architecture"))
|
|
249
|
+
|
|
250
|
+
findings = analysis.get("findings") or analysis.get("issues") or []
|
|
251
|
+
if findings:
|
|
252
|
+
print("\nFindings:")
|
|
253
|
+
for issue in findings[:15]:
|
|
254
|
+
print_issue(issue)
|
|
255
|
+
|
|
256
|
+
if analysis["cycles"]:
|
|
257
|
+
print("\nCycles:")
|
|
258
|
+
for cycle in analysis["cycles"][:10]:
|
|
259
|
+
print("- " + " -> ".join(cycle))
|
|
260
|
+
|
|
261
|
+
if analysis["hotspot_files"]:
|
|
262
|
+
print("\nHotspots:")
|
|
263
|
+
for hotspot in analysis["hotspot_files"][:10]:
|
|
264
|
+
print(f"- {hotspot['file']} ({hotspot['dependency_count']} dependents)")
|
|
265
|
+
|
|
266
|
+
if analysis.get("file_risk_ranking"):
|
|
267
|
+
print("\nTop Architectural Risks:")
|
|
268
|
+
for index, file_risk in enumerate(analysis["file_risk_ranking"][:10], start=1):
|
|
269
|
+
print(f"{index}. {file_risk['file']} ({file_risk['risk_score']})")
|
|
270
|
+
if file_risk.get("reasons"):
|
|
271
|
+
print(f" Reasons: {', '.join(file_risk['reasons'])}")
|
|
272
|
+
|
|
273
|
+
if analysis.get("refactor_recommendations"):
|
|
274
|
+
print("\nRecommended Refactors:")
|
|
275
|
+
for recommendation in analysis["refactor_recommendations"][:5]:
|
|
276
|
+
print(f"- {recommendation['title']}")
|
|
277
|
+
print(f" Impact: {recommendation.get('impact', 'medium').title()}")
|
|
278
|
+
print(f" Benefit: {recommendation['expected_benefit']}")
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def print_report(report):
|
|
282
|
+
print_header("Architecture Report")
|
|
283
|
+
summary = report["executive_summary"]
|
|
284
|
+
print(f"Rating: {report['overall_architecture_rating']}/100 ({summary['rating_label']})")
|
|
285
|
+
print(summary["status"])
|
|
286
|
+
print(
|
|
287
|
+
f"Issues: {summary['total_issues']} "
|
|
288
|
+
f"(critical {summary['critical_issues']}, high {summary['high_issues']}, "
|
|
289
|
+
f"medium {summary['medium_issues']}, low {summary['low_issues']})"
|
|
290
|
+
)
|
|
291
|
+
print(f"Cycles: {summary['cycle_count']}")
|
|
292
|
+
print(f"Hotspots: {summary['hotspot_count']}")
|
|
293
|
+
|
|
294
|
+
if report["prioritized_refactor_plan"]:
|
|
295
|
+
print("\nRefactor plan:")
|
|
296
|
+
for item in report["prioritized_refactor_plan"]:
|
|
297
|
+
print(f"{item['priority']}. {item['title']}")
|
|
298
|
+
print(f" Reason: {item['reason']}")
|
|
299
|
+
print(f" Action: {item['action']}")
|
|
300
|
+
|
|
301
|
+
if report["top_10_issues"]:
|
|
302
|
+
print("\nTop issues:")
|
|
303
|
+
for issue in report["top_10_issues"]:
|
|
304
|
+
print_issue(issue)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def is_snapshot_file(path):
|
|
308
|
+
if not os.path.isfile(path):
|
|
309
|
+
return False
|
|
310
|
+
if not path.endswith(".json"):
|
|
311
|
+
return False
|
|
312
|
+
try:
|
|
313
|
+
with open(path, "r", encoding="utf-8") as f:
|
|
314
|
+
data = json.load(f)
|
|
315
|
+
except (OSError, json.JSONDecodeError):
|
|
316
|
+
return False
|
|
317
|
+
return "architecture_score" in data and "dependency_graph" in data
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def load_comparison_target(path):
|
|
321
|
+
if os.path.isdir(path):
|
|
322
|
+
analysis = analyze_project_architecture(path)
|
|
323
|
+
return snapshot_from_analysis(analysis, name=path)
|
|
324
|
+
|
|
325
|
+
if is_snapshot_file(path):
|
|
326
|
+
snapshot = load_snapshot_file(path)
|
|
327
|
+
snapshot["file"] = os.path.basename(path)
|
|
328
|
+
return snapshot
|
|
329
|
+
|
|
330
|
+
raise ValueError(f"Comparison target is not a directory or architecture snapshot: {path}")
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def print_comparison(comparison):
|
|
334
|
+
print_header("Architecture Comparison")
|
|
335
|
+
print(f"From: {comparison.get('file1')}")
|
|
336
|
+
print(f"To: {comparison.get('file2')}")
|
|
337
|
+
print(f"Architecture score: {comparison['previous_score']} -> {comparison['current_score']} ({comparison['score_difference']:+})")
|
|
338
|
+
print(f"Structural drift score: {comparison['structural_drift_score']}/100")
|
|
339
|
+
|
|
340
|
+
narrative = comparison.get("architecture_narrative", {})
|
|
341
|
+
if narrative:
|
|
342
|
+
print(f"Trend: {narrative.get('trend_direction')}")
|
|
343
|
+
print(f"Subsystem: {narrative.get('degrading_subsystem')}")
|
|
344
|
+
print(f"Pattern: {narrative.get('structural_pattern')}")
|
|
345
|
+
print(narrative.get("explanation"))
|
|
346
|
+
|
|
347
|
+
print(
|
|
348
|
+
"\nChanges: "
|
|
349
|
+
f"+{len(comparison['added_dependencies'])} dependencies, "
|
|
350
|
+
f"-{len(comparison['removed_dependencies'])} dependencies, "
|
|
351
|
+
f"+{len(comparison['new_cycles'])} cycles, "
|
|
352
|
+
f"-{len(comparison['resolved_cycles'])} cycles"
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
causes = comparison["root_cause_analysis"]["primary_cause_files"]
|
|
356
|
+
if causes:
|
|
357
|
+
print("\nPrimary cause files:")
|
|
358
|
+
for file in causes:
|
|
359
|
+
print(f"- {file}")
|
|
360
|
+
|
|
361
|
+
if comparison["refactor_plan"]:
|
|
362
|
+
print("\nRefactor first:")
|
|
363
|
+
for item in comparison["refactor_plan"][:5]:
|
|
364
|
+
print(f"- [{item['priority_score']}/10] {item['file']}")
|
|
365
|
+
print(f" Reason: {item['reason']}")
|
|
366
|
+
print(f" Action: {item['action']}")
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def short_commit(commit_hash):
|
|
370
|
+
if not commit_hash:
|
|
371
|
+
return "unknown"
|
|
372
|
+
return commit_hash[:12]
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def score_bar(score, width=30):
|
|
376
|
+
filled = max(0, min(width, int(round((score / 100) * width))))
|
|
377
|
+
return "#" * filled + "-" * (width - filled)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def print_git_drift(drift, evolution_report, snapshot_count):
|
|
381
|
+
print_header("Git Architecture Drift")
|
|
382
|
+
print(f"Commits analyzed: {snapshot_count}")
|
|
383
|
+
print(f"Overall health score: {evolution_report['overall_system_health_score']}/100")
|
|
384
|
+
|
|
385
|
+
best = evolution_report.get("best_architecture_state")
|
|
386
|
+
worst = evolution_report.get("worst_architecture_state")
|
|
387
|
+
regression = evolution_report.get("biggest_regression_commit")
|
|
388
|
+
|
|
389
|
+
if best:
|
|
390
|
+
print(f"Best state: {short_commit(best['commit'])} ({best['architecture_score']}/100)")
|
|
391
|
+
if worst:
|
|
392
|
+
print(f"Worst state: {short_commit(worst['commit'])} ({worst['architecture_score']}/100)")
|
|
393
|
+
if regression:
|
|
394
|
+
print(f"Biggest regression: {short_commit(regression['commit'])} ({regression['score_delta']:+})")
|
|
395
|
+
|
|
396
|
+
drift_points = drift.get("drift_points", [])
|
|
397
|
+
if not drift_points:
|
|
398
|
+
print("\nNo architecture drift points detected.")
|
|
399
|
+
return
|
|
400
|
+
|
|
401
|
+
print("\nDrift points:")
|
|
402
|
+
for point in drift_points:
|
|
403
|
+
print(f"- [{point['severity']}] {short_commit(point['commit'])} ({point.get('score_delta', 0):+})")
|
|
404
|
+
print(f" {point['reason']}")
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def print_history(timeline_report):
|
|
408
|
+
print_header("Architecture History")
|
|
409
|
+
print(f"Trend: {timeline_report['trend']}")
|
|
410
|
+
print(f"Volatility: {timeline_report['volatility_score']}/100")
|
|
411
|
+
print(f"Structural stability: {timeline_report['structural_stability_metric']}/100")
|
|
412
|
+
|
|
413
|
+
timeline = timeline_report.get("timeline", [])
|
|
414
|
+
if not timeline:
|
|
415
|
+
print("\nNo committed architecture snapshots found.")
|
|
416
|
+
return
|
|
417
|
+
|
|
418
|
+
print("\nScore trend:")
|
|
419
|
+
for item in timeline:
|
|
420
|
+
score = item["architecture_score"]
|
|
421
|
+
print(
|
|
422
|
+
f"{short_commit(item['commit'])} "
|
|
423
|
+
f"{score:>3}/100 "
|
|
424
|
+
f"{score_bar(score)} "
|
|
425
|
+
f"{item.get('architecture_type') or 'unknown'}"
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
if timeline_report.get("regression_points"):
|
|
429
|
+
print("\nRegressions:")
|
|
430
|
+
for item in timeline_report["regression_points"]:
|
|
431
|
+
print(f"- {short_commit(item['commit'])}: {item['score_delta']:+} -> {item['architecture_score']}/100")
|
|
432
|
+
|
|
433
|
+
if timeline_report.get("improvement_points"):
|
|
434
|
+
print("\nImprovements:")
|
|
435
|
+
for item in timeline_report["improvement_points"]:
|
|
436
|
+
print(f"- {short_commit(item['commit'])}: {item['score_delta']:+} -> {item['architecture_score']}/100")
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def print_architecture_blame(result):
|
|
440
|
+
print_header("Architecture Blame")
|
|
441
|
+
print(f"File: {result['file']}")
|
|
442
|
+
|
|
443
|
+
commits = result.get("degrading_commits", [])
|
|
444
|
+
if not commits:
|
|
445
|
+
print("No commits were found that degraded this file/module.")
|
|
446
|
+
return
|
|
447
|
+
|
|
448
|
+
for item in commits:
|
|
449
|
+
print(f"- {short_commit(item['commit'])} ({item['score_delta']:+})")
|
|
450
|
+
for reason in item.get("reasons", []):
|
|
451
|
+
print(f" {reason}")
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def print_pr_review(result):
|
|
455
|
+
print(format_github_check(result).rstrip())
|
|
456
|
+
print("")
|
|
457
|
+
print("Status: {0}".format(result.get("status") or "ERROR"))
|
|
458
|
+
if result.get("base_sha") or result.get("base_ref"):
|
|
459
|
+
print("Base: {0}".format(result.get("base_sha") or result.get("base_ref")))
|
|
460
|
+
if result.get("head_sha") or result.get("head_ref"):
|
|
461
|
+
print("Head: {0}".format(result.get("head_sha") or result.get("head_ref")))
|
|
462
|
+
if result.get("baseline_source"):
|
|
463
|
+
print("Baseline source: {0}".format(result["baseline_source"]))
|
|
464
|
+
if result.get("baseline_location"):
|
|
465
|
+
print("Baseline location: {0}".format(result["baseline_location"]))
|
|
466
|
+
if result.get("comparison_mode") == "base_tree":
|
|
467
|
+
print("Compared against: base tree (only changes introduced by this PR count)")
|
|
468
|
+
elif result.get("comparison_mode") == "baseline_snapshot":
|
|
469
|
+
print("Compared against: saved baseline edges (base tree could not be analyzed)")
|
|
470
|
+
if result.get("base_analysis_error"):
|
|
471
|
+
print("Base analysis error: {0}".format(result["base_analysis_error"]))
|
|
472
|
+
renamed = result.get("renamed_files") or []
|
|
473
|
+
if renamed:
|
|
474
|
+
print("Renamed files: {0}".format(len(renamed)))
|
|
475
|
+
if result.get("working_tree_dirty"):
|
|
476
|
+
print("Note: working tree has uncommitted changes; analysis used the current files.")
|
|
477
|
+
incremental = result.get("incremental") or {}
|
|
478
|
+
if incremental:
|
|
479
|
+
print_incremental(incremental)
|
|
480
|
+
changed = result.get("changed_files") or []
|
|
481
|
+
if changed:
|
|
482
|
+
print("\nChanged files: {0}".format(len(changed)))
|
|
483
|
+
for path in changed[:20]:
|
|
484
|
+
print("- {0}".format(path))
|
|
485
|
+
if result.get("error"):
|
|
486
|
+
print("\nError: {0}".format(result["error"]))
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
def print_evolution_report(evolution):
|
|
490
|
+
print_header("Architecture Evolution Report")
|
|
491
|
+
print(f"Trend: {evolution['trend']}")
|
|
492
|
+
print(f"Stability Score: {evolution['stability_score']}/100")
|
|
493
|
+
|
|
494
|
+
timeline = evolution.get("architecture_timeline", [])
|
|
495
|
+
if timeline:
|
|
496
|
+
first = timeline[0]
|
|
497
|
+
last = timeline[-1]
|
|
498
|
+
print(
|
|
499
|
+
f"Score: {first['architecture_score']} -> {last['architecture_score']} "
|
|
500
|
+
f"({last['architecture_score'] - first['architecture_score']:+})"
|
|
501
|
+
)
|
|
502
|
+
print(f"Commits analyzed: {len(timeline)}")
|
|
503
|
+
|
|
504
|
+
if evolution.get("drift_events"):
|
|
505
|
+
print("\nMajor Drift Events:")
|
|
506
|
+
for event in evolution["drift_events"][:10]:
|
|
507
|
+
print(f"- [{event['severity']}] {event['event']} at {short_commit(event['commit'])}")
|
|
508
|
+
if event.get("details"):
|
|
509
|
+
print(f" {event['details']}")
|
|
510
|
+
|
|
511
|
+
if evolution.get("degrading_subsystems"):
|
|
512
|
+
print("\nHighest-Risk Subsystems:")
|
|
513
|
+
for index, subsystem in enumerate(evolution["degrading_subsystems"][:5], start=1):
|
|
514
|
+
print(f"{index}. {subsystem['subsystem']} ({subsystem['trend']}, risk delta {subsystem['risk_delta']:+})")
|
|
515
|
+
elif evolution.get("subsystem_health"):
|
|
516
|
+
print("\nHighest-Risk Subsystems:")
|
|
517
|
+
ranked = sorted(
|
|
518
|
+
evolution["subsystem_health"].items(),
|
|
519
|
+
key=lambda item: (-item[1].get("risk_delta", 0), item[0]),
|
|
520
|
+
)
|
|
521
|
+
for index, (subsystem, data) in enumerate(ranked[:5], start=1):
|
|
522
|
+
print(f"{index}. {subsystem} ({data['trend']}, risk delta {data['risk_delta']:+})")
|
|
523
|
+
|
|
524
|
+
if evolution.get("repeat_offenders"):
|
|
525
|
+
print("\nRepeat Offenders:")
|
|
526
|
+
for index, offender in enumerate(evolution["repeat_offenders"][:10], start=1):
|
|
527
|
+
print(f"{index}. {offender['file']} ({offender['offender_score']})")
|
|
528
|
+
if offender.get("reasons"):
|
|
529
|
+
print(f" Reasons: {', '.join(offender['reasons'])}")
|
|
530
|
+
|
|
531
|
+
if evolution.get("root_causes"):
|
|
532
|
+
print("\nRoot Cause Signals:")
|
|
533
|
+
for insight in evolution["root_causes"]:
|
|
534
|
+
print(f"- {insight}")
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
def print_stability_report(stability):
|
|
538
|
+
print_header("Architecture Stability Report")
|
|
539
|
+
print(f"Stability Score: {stability['stability_score']}/100")
|
|
540
|
+
print(f"Commits analyzed: {stability.get('commit_count', 0)}")
|
|
541
|
+
|
|
542
|
+
if stability.get("volatile_files"):
|
|
543
|
+
print("\nMost Volatile Files:")
|
|
544
|
+
for index, item in enumerate(stability["volatile_files"][:10], start=1):
|
|
545
|
+
print(f"{index}. {item['file']} ({item['volatility_score']})")
|
|
546
|
+
if item.get("reasons"):
|
|
547
|
+
print(f" Reasons: {', '.join(item['reasons'])}")
|
|
548
|
+
|
|
549
|
+
if stability.get("fragile_subsystems"):
|
|
550
|
+
print("\nFragile Subsystems:")
|
|
551
|
+
for index, item in enumerate(stability["fragile_subsystems"][:5], start=1):
|
|
552
|
+
print(f"{index}. {item['subsystem']} ({item['fragility_score']}, {item['trend']})")
|
|
553
|
+
|
|
554
|
+
if stability.get("blast_radius_ranking"):
|
|
555
|
+
print("\nLargest Blast Radius:")
|
|
556
|
+
for index, item in enumerate(stability["blast_radius_ranking"][:10], start=1):
|
|
557
|
+
print(f"{index}. {item['file']} ({item['blast_radius']}, {item['blast_radius_score']})")
|
|
558
|
+
|
|
559
|
+
if stability.get("governance_insights"):
|
|
560
|
+
print("\nGovernance Insights:")
|
|
561
|
+
for insight in stability["governance_insights"]:
|
|
562
|
+
print(f"- {insight}")
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
def print_decision_report(report):
|
|
566
|
+
print_header("ARCHITECTURE DECISION REPORT")
|
|
567
|
+
|
|
568
|
+
decisions = report.get("decisions", [])
|
|
569
|
+
summary = report.get("executive_summary", {})
|
|
570
|
+
impact = report.get("impact_overview", {})
|
|
571
|
+
|
|
572
|
+
if decisions:
|
|
573
|
+
print("\nTop Actions:")
|
|
574
|
+
for index, decision in enumerate(decisions[:10], start=1):
|
|
575
|
+
print(f"{index}. {decision['action']} ({decision['priority_score']})")
|
|
576
|
+
print(f" Impact: {decision['impact_level'].title()} | Effort: {decision['effort_estimate'].title()}")
|
|
577
|
+
if decision.get("affected_files"):
|
|
578
|
+
print(f" Files: {', '.join(decision['affected_files'][:5])}")
|
|
579
|
+
if decision.get("source_signals"):
|
|
580
|
+
print(f" Signals: {', '.join(decision['source_signals'])}")
|
|
581
|
+
context = decision.get("explanation_context", {})
|
|
582
|
+
if context.get("why_it_matters"):
|
|
583
|
+
print(f" Why: {context['why_it_matters']}")
|
|
584
|
+
|
|
585
|
+
print("\nImpact Overview:")
|
|
586
|
+
print(f"- High impact: {impact.get('high', 0)}")
|
|
587
|
+
print(f"- Medium impact: {impact.get('medium', 0)}")
|
|
588
|
+
print(f"- Low impact: {impact.get('low', 0)}")
|
|
589
|
+
|
|
590
|
+
if report.get("key_risks"):
|
|
591
|
+
print("\nKey Risks:")
|
|
592
|
+
for risk in report["key_risks"]:
|
|
593
|
+
print(f"- {risk}")
|
|
594
|
+
|
|
595
|
+
print("\nExecutive Summary:")
|
|
596
|
+
health = summary.get("current_architecture_health", {})
|
|
597
|
+
if health:
|
|
598
|
+
print(f"- Current health: {health.get('score', 0)}/100 architecture, {health.get('stability_score', 0)}/100 stability")
|
|
599
|
+
if summary.get("main_structural_weakness"):
|
|
600
|
+
print(f"- Main structural weakness: {summary['main_structural_weakness']}")
|
|
601
|
+
if summary.get("overall_trajectory"):
|
|
602
|
+
print(f"- Overall trajectory: {summary['overall_trajectory']}")
|
|
603
|
+
for action in summary.get("top_3_recommended_actions", []):
|
|
604
|
+
print(f"- Recommended: {action}")
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
def print_architecture_explanation(explanation):
|
|
608
|
+
print_header("ARCHITECTURE EXPLANATION")
|
|
609
|
+
|
|
610
|
+
print("\nSystem Overview:")
|
|
611
|
+
print(explanation["architecture_summary"])
|
|
612
|
+
|
|
613
|
+
if explanation.get("key_subsystems"):
|
|
614
|
+
print("\nSubsystem Breakdown:")
|
|
615
|
+
for subsystem in explanation["key_subsystems"][:8]:
|
|
616
|
+
print(f"- {subsystem['subsystem']}/ ({subsystem['risk_level']} risk)")
|
|
617
|
+
print(f" {subsystem['story']}")
|
|
618
|
+
|
|
619
|
+
if explanation.get("core_patterns"):
|
|
620
|
+
print("\nKey Architectural Issues:")
|
|
621
|
+
for pattern in explanation["core_patterns"]:
|
|
622
|
+
print(f"- {pattern['name']}: {pattern['explanation']}")
|
|
623
|
+
|
|
624
|
+
if explanation.get("coupling_explanation"):
|
|
625
|
+
print("\nDependency Narrative:")
|
|
626
|
+
print(explanation.get("dependency_narrative", ""))
|
|
627
|
+
for item in explanation["coupling_explanation"][:8]:
|
|
628
|
+
print(f"- {item['explanation']}")
|
|
629
|
+
|
|
630
|
+
if explanation.get("risk_narrative"):
|
|
631
|
+
print("\nRisk Narrative:")
|
|
632
|
+
print(explanation["risk_narrative"])
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
def command_analyze(args):
|
|
636
|
+
analysis = analyze_project_architecture(
|
|
637
|
+
args.path,
|
|
638
|
+
selected_paths=args.select or None,
|
|
639
|
+
expand_related=not args.no_expand,
|
|
640
|
+
)
|
|
641
|
+
print_analysis(analysis)
|
|
642
|
+
return 0
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
def command_baseline(args):
|
|
646
|
+
analysis = analyze_project_architecture(
|
|
647
|
+
args.path,
|
|
648
|
+
selected_paths=args.select or None,
|
|
649
|
+
expand_related=not args.no_expand,
|
|
650
|
+
)
|
|
651
|
+
baseline = analysis.get("architecture")
|
|
652
|
+
if not baseline:
|
|
653
|
+
print("Error: analysis did not produce an architecture baseline.", file=sys.stderr)
|
|
654
|
+
return 1
|
|
655
|
+
destination = save_architecture_baseline(baseline, destination=args.output)
|
|
656
|
+
print_header("Architecture Baseline Saved")
|
|
657
|
+
print("File: {0}".format(destination))
|
|
658
|
+
print_scope(analysis.get("scope"))
|
|
659
|
+
print_architecture(baseline)
|
|
660
|
+
return 0
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def command_review(args):
|
|
664
|
+
result = review_working_tree(
|
|
665
|
+
args.path,
|
|
666
|
+
baseline_path=args.against,
|
|
667
|
+
selected_paths=args.select or None,
|
|
668
|
+
expand_related=not args.no_expand,
|
|
669
|
+
)
|
|
670
|
+
if result["status"] != "ok":
|
|
671
|
+
print("Error: {0}".format(result["error"]), file=sys.stderr)
|
|
672
|
+
return 1
|
|
673
|
+
print_review(result["comparison"])
|
|
674
|
+
return result["exit_code"]
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
def command_report(args):
|
|
678
|
+
analysis = analyze_project_architecture(
|
|
679
|
+
args.path,
|
|
680
|
+
selected_paths=getattr(args, "select", None) or None,
|
|
681
|
+
expand_related=not getattr(args, "no_expand", False),
|
|
682
|
+
)
|
|
683
|
+
report = build_architecture_report(analysis)
|
|
684
|
+
print_report(report)
|
|
685
|
+
return 0
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def command_compare(args):
|
|
689
|
+
before = load_comparison_target(args.path)
|
|
690
|
+
after = load_comparison_target(args.path2)
|
|
691
|
+
comparison = compare_snapshot_data(before, after)
|
|
692
|
+
print_comparison(comparison)
|
|
693
|
+
return 0
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
def command_git_drift(args):
|
|
697
|
+
snapshots = extract_git_snapshots(args.path)
|
|
698
|
+
drift = detect_architecture_drift(snapshots)
|
|
699
|
+
evolution_report = build_evolution_report(snapshots)
|
|
700
|
+
print_git_drift(drift, evolution_report, len(snapshots))
|
|
701
|
+
return 0
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
def command_history(args):
|
|
705
|
+
snapshots = extract_git_snapshots(args.path)
|
|
706
|
+
timeline = build_architecture_timeline(snapshots)
|
|
707
|
+
print_history(timeline)
|
|
708
|
+
return 0
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
def command_blame_architecture(args):
|
|
712
|
+
result = blame_architecture_file(args.file)
|
|
713
|
+
print_architecture_blame(result)
|
|
714
|
+
return 0
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
def _pr_result_for_json(result):
|
|
718
|
+
payload = dict(result)
|
|
719
|
+
payload.pop("architecture", None)
|
|
720
|
+
return payload
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
def command_pr_check(args):
|
|
724
|
+
result = review_pull_request(
|
|
725
|
+
getattr(args, "path", ".") or ".",
|
|
726
|
+
args.base_branch,
|
|
727
|
+
args.head_branch,
|
|
728
|
+
baseline_path=getattr(args, "against", None),
|
|
729
|
+
)
|
|
730
|
+
sarif_path = getattr(args, "sarif", None)
|
|
731
|
+
if sarif_path:
|
|
732
|
+
write_sarif(result, sarif_path)
|
|
733
|
+
if getattr(args, "format", "text") == "json":
|
|
734
|
+
print(json.dumps(_pr_result_for_json(result), indent=2, sort_keys=True, default=str))
|
|
735
|
+
else:
|
|
736
|
+
print_pr_review(result)
|
|
737
|
+
if os.environ.get("GITHUB_ACTIONS") or os.environ.get("GITHUB_STEP_SUMMARY"):
|
|
738
|
+
if getattr(args, "format", "text") == "json":
|
|
739
|
+
# Keep stdout pure JSON; annotations still go to the summary file.
|
|
740
|
+
with redirect_stdout(sys.stderr):
|
|
741
|
+
write_github_output(result)
|
|
742
|
+
else:
|
|
743
|
+
write_github_output(result)
|
|
744
|
+
write_step_outputs(result, sarif_path)
|
|
745
|
+
return exit_code_for(result)
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
def command_evolution(args):
|
|
749
|
+
snapshots = extract_git_snapshots(args.path)
|
|
750
|
+
evolution = analyze_architecture_evolution(snapshots)
|
|
751
|
+
print_evolution_report(evolution)
|
|
752
|
+
return 0
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
def command_stability(args):
|
|
756
|
+
stability = analyze_architecture_stability(args.path)
|
|
757
|
+
print_stability_report(stability)
|
|
758
|
+
return 0
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
def command_decisions(args):
|
|
762
|
+
report = generate_architecture_decisions(args.path)
|
|
763
|
+
explanation = generate_architecture_explanation(args.path)
|
|
764
|
+
report = attach_explanation_context_to_decisions(report, explanation)
|
|
765
|
+
print_decision_report(report)
|
|
766
|
+
return 0
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
def command_explain(args):
|
|
770
|
+
explanation = generate_architecture_explanation(args.path)
|
|
771
|
+
print_architecture_explanation(explanation)
|
|
772
|
+
return 0
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
def command_web(args):
|
|
776
|
+
try:
|
|
777
|
+
import uvicorn
|
|
778
|
+
from adre.web import app
|
|
779
|
+
except ImportError as exc:
|
|
780
|
+
print(
|
|
781
|
+
"Error: the web UI needs optional dependencies ({0}). "
|
|
782
|
+
"Install them with: pip install 'adre-cli[web]'".format(exc.name or exc),
|
|
783
|
+
file=sys.stderr,
|
|
784
|
+
)
|
|
785
|
+
return 1
|
|
786
|
+
host = (args.host or "127.0.0.1").strip()
|
|
787
|
+
if host not in {"127.0.0.1", "localhost", "::1"}:
|
|
788
|
+
print(
|
|
789
|
+
"Warning: binding to {0} exposes the web UI beyond this machine. It can save files, "
|
|
790
|
+
"clone repositories and open your editor; only do this on a trusted network.".format(host),
|
|
791
|
+
file=sys.stderr,
|
|
792
|
+
)
|
|
793
|
+
if host not in {"0.0.0.0", "::"}:
|
|
794
|
+
# Let requests addressed to that host name through the Host check.
|
|
795
|
+
existing = os.environ.get("ADRE_WEB_ALLOWED_HOSTS", "")
|
|
796
|
+
os.environ["ADRE_WEB_ALLOWED_HOSTS"] = ",".join(item for item in (existing, host) if item)
|
|
797
|
+
uvicorn.run(app, host=host, port=args.port)
|
|
798
|
+
return 0
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
def build_parser():
|
|
802
|
+
parser = argparse.ArgumentParser(prog="adre", description="ADRE CLI")
|
|
803
|
+
parser.add_argument(
|
|
804
|
+
"--version",
|
|
805
|
+
action="version",
|
|
806
|
+
version="%(prog)s {0} (analyzer {1})".format(__version__, ANALYZER_VERSION),
|
|
807
|
+
)
|
|
808
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
809
|
+
|
|
810
|
+
analyze_parser = subparsers.add_parser("analyze", help="Analyze current code. Does not update the saved baseline.")
|
|
811
|
+
analyze_parser.add_argument("path")
|
|
812
|
+
analyze_parser.add_argument(
|
|
813
|
+
"--select",
|
|
814
|
+
nargs="+",
|
|
815
|
+
default=None,
|
|
816
|
+
help="Limit analysis to files or directories inside the project. Related imports are expanded unless --no-expand is set.",
|
|
817
|
+
)
|
|
818
|
+
analyze_parser.add_argument(
|
|
819
|
+
"--no-expand",
|
|
820
|
+
action="store_true",
|
|
821
|
+
help="Do not add imported/related files to a --select analysis.",
|
|
822
|
+
)
|
|
823
|
+
analyze_parser.set_defaults(func=command_analyze)
|
|
824
|
+
|
|
825
|
+
baseline_parser = subparsers.add_parser("baseline", help="Save the current architecture as the accepted baseline")
|
|
826
|
+
baseline_parser.add_argument("path")
|
|
827
|
+
baseline_parser.add_argument("--select", nargs="+", default=None)
|
|
828
|
+
baseline_parser.add_argument("--no-expand", action="store_true")
|
|
829
|
+
baseline_parser.add_argument("--output", help="Baseline JSON path (default: <project>/.adre/baseline.json)")
|
|
830
|
+
baseline_parser.set_defaults(func=command_baseline)
|
|
831
|
+
|
|
832
|
+
review_parser = subparsers.add_parser("review", help="Compare current analysis against a saved architecture baseline")
|
|
833
|
+
review_parser.add_argument("path")
|
|
834
|
+
review_parser.add_argument("--select", nargs="+", default=None)
|
|
835
|
+
review_parser.add_argument("--no-expand", action="store_true")
|
|
836
|
+
review_parser.add_argument("--against", help="Baseline JSON path (default: <project>/.adre/baseline.json)")
|
|
837
|
+
review_parser.set_defaults(func=command_review)
|
|
838
|
+
|
|
839
|
+
report_parser = subparsers.add_parser("report", help="Print a terminal architecture report")
|
|
840
|
+
report_parser.add_argument("path")
|
|
841
|
+
report_parser.add_argument("--select", nargs="+", default=None)
|
|
842
|
+
report_parser.add_argument("--no-expand", action="store_true")
|
|
843
|
+
report_parser.set_defaults(func=command_report)
|
|
844
|
+
|
|
845
|
+
compare_parser = subparsers.add_parser("compare", help="Compare two snapshots or two directories")
|
|
846
|
+
compare_parser.add_argument("path")
|
|
847
|
+
compare_parser.add_argument("path2")
|
|
848
|
+
compare_parser.set_defaults(func=command_compare)
|
|
849
|
+
|
|
850
|
+
git_drift_parser = subparsers.add_parser("git-drift", help="Analyze architecture drift across git history")
|
|
851
|
+
git_drift_parser.add_argument("path")
|
|
852
|
+
git_drift_parser.set_defaults(func=command_git_drift)
|
|
853
|
+
|
|
854
|
+
history_parser = subparsers.add_parser("history", help="Show architecture score timeline across git history")
|
|
855
|
+
history_parser.add_argument("path")
|
|
856
|
+
history_parser.set_defaults(func=command_history)
|
|
857
|
+
|
|
858
|
+
evolution_parser = subparsers.add_parser("evolution", help="Explain architecture evolution across git history")
|
|
859
|
+
evolution_parser.add_argument("path")
|
|
860
|
+
evolution_parser.set_defaults(func=command_evolution)
|
|
861
|
+
|
|
862
|
+
stability_parser = subparsers.add_parser("stability", help="Show architecture ownership and stability intelligence")
|
|
863
|
+
stability_parser.add_argument("path")
|
|
864
|
+
stability_parser.set_defaults(func=command_stability)
|
|
865
|
+
|
|
866
|
+
decisions_parser = subparsers.add_parser("decisions", help="Show unified architecture decision report")
|
|
867
|
+
decisions_parser.add_argument("path")
|
|
868
|
+
decisions_parser.set_defaults(func=command_decisions)
|
|
869
|
+
|
|
870
|
+
explain_parser = subparsers.add_parser("explain", help="Explain how a project architecture is structured")
|
|
871
|
+
explain_parser.add_argument("path")
|
|
872
|
+
explain_parser.set_defaults(func=command_explain)
|
|
873
|
+
|
|
874
|
+
blame_parser = subparsers.add_parser("blame-architecture", help="Show commits that degraded a file/module")
|
|
875
|
+
blame_parser.add_argument("file")
|
|
876
|
+
blame_parser.set_defaults(func=command_blame_architecture)
|
|
877
|
+
|
|
878
|
+
pr_check_parser = subparsers.add_parser(
|
|
879
|
+
"pr-check",
|
|
880
|
+
help="Review HEAD against the accepted architecture baseline for a pull request",
|
|
881
|
+
)
|
|
882
|
+
pr_check_parser.add_argument("base_branch")
|
|
883
|
+
pr_check_parser.add_argument("head_branch", nargs="?", default="HEAD")
|
|
884
|
+
pr_check_parser.add_argument(
|
|
885
|
+
"--path",
|
|
886
|
+
default=".",
|
|
887
|
+
help="Project path inside the git repository to analyze (default: current directory)",
|
|
888
|
+
)
|
|
889
|
+
pr_check_parser.add_argument("--against", help="Baseline JSON path (default: base ref .adre/baseline.json)")
|
|
890
|
+
pr_check_parser.add_argument("--format", choices=["text", "json"], default="text", help="Output format (default: text)")
|
|
891
|
+
pr_check_parser.add_argument("--sarif", metavar="PATH", help="Also write findings as SARIF 2.1.0 to PATH")
|
|
892
|
+
pr_check_parser.set_defaults(func=command_pr_check)
|
|
893
|
+
|
|
894
|
+
pr_review_parser = subparsers.add_parser("pr-review", help="Same as pr-check: compare a PR against the accepted baseline")
|
|
895
|
+
pr_review_parser.add_argument("base_branch")
|
|
896
|
+
pr_review_parser.add_argument("head_branch", nargs="?", default="HEAD")
|
|
897
|
+
pr_review_parser.add_argument("--path", default=".")
|
|
898
|
+
pr_review_parser.add_argument("--against", default=None)
|
|
899
|
+
pr_review_parser.add_argument("--format", choices=["text", "json"], default="text", help="Output format (default: text)")
|
|
900
|
+
pr_review_parser.add_argument("--sarif", metavar="PATH", help="Also write findings as SARIF 2.1.0 to PATH")
|
|
901
|
+
pr_review_parser.set_defaults(func=command_pr_check)
|
|
902
|
+
|
|
903
|
+
web_parser = subparsers.add_parser("web", help="Start the local web UI (needs: pip install 'adre-cli[web]')")
|
|
904
|
+
web_parser.add_argument("--host", default="127.0.0.1", help="Interface to bind (default: 127.0.0.1, local only)")
|
|
905
|
+
web_parser.add_argument("--port", type=int, default=8000)
|
|
906
|
+
web_parser.set_defaults(func=command_web)
|
|
907
|
+
|
|
908
|
+
return parser
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
def main(argv=None):
|
|
912
|
+
parser = build_parser()
|
|
913
|
+
args = parser.parse_args(argv)
|
|
914
|
+
|
|
915
|
+
try:
|
|
916
|
+
return args.func(args)
|
|
917
|
+
except Exception as exc:
|
|
918
|
+
print(f"Error: {exc}", file=sys.stderr)
|
|
919
|
+
return 1
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
if __name__ == "__main__":
|
|
923
|
+
raise SystemExit(main())
|