adre-cli 0.2.0__tar.gz → 0.3.0__tar.gz

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 (74) hide show
  1. {adre_cli-0.2.0/adre_cli.egg-info → adre_cli-0.3.0}/PKG-INFO +54 -24
  2. {adre_cli-0.2.0 → adre_cli-0.3.0}/README.md +51 -21
  3. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/__init__.py +1 -1
  4. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/cli.py +153 -17
  5. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/github_check.py +8 -2
  6. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/incremental.py +17 -0
  7. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/pr_comment.py +2 -1
  8. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/pr_review.py +55 -20
  9. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/repositories.py +38 -5
  10. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/review.py +15 -3
  11. adre_cli-0.3.0/adre/core/setup.py +79 -0
  12. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/web.py +70 -56
  13. {adre_cli-0.2.0 → adre_cli-0.3.0/adre_cli.egg-info}/PKG-INFO +54 -24
  14. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre_cli.egg-info/SOURCES.txt +2 -0
  15. {adre_cli-0.2.0 → adre_cli-0.3.0}/pyproject.toml +5 -2
  16. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_baseline.py +12 -4
  17. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_gaps.py +7 -4
  18. adre_cli-0.3.0/tests/test_onboarding.py +242 -0
  19. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_packaging.py +5 -3
  20. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_pr_review.py +6 -0
  21. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_recall.py +6 -0
  22. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_web.py +18 -11
  23. {adre_cli-0.2.0 → adre_cli-0.3.0}/LICENSE +0 -0
  24. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/analyzers/__init__.py +0 -0
  25. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/analyzers/architecture.py +0 -0
  26. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/analyzers/findings.py +0 -0
  27. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/analyzers/inference.py +0 -0
  28. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/__init__.py +0 -0
  29. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/accepted.py +0 -0
  30. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/adaptive.py +0 -0
  31. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/baseline.py +0 -0
  32. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/config.py +0 -0
  33. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/decision_engine.py +0 -0
  34. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/declared.py +0 -0
  35. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/evolution_intelligence.py +0 -0
  36. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/explainer.py +0 -0
  37. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/git_intelligence.py +0 -0
  38. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/layers.py +0 -0
  39. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/pr_intelligence.py +0 -0
  40. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/prioritization.py +0 -0
  41. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/project.py +0 -0
  42. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/refactor_intelligence.py +0 -0
  43. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/rules_shared.py +0 -0
  44. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/sarif.py +0 -0
  45. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/scope.py +0 -0
  46. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/severity.py +0 -0
  47. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/snapshots.py +0 -0
  48. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/core/stability_intelligence.py +0 -0
  49. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/graph/__init__.py +0 -0
  50. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/graph/dependencies.py +0 -0
  51. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/parsers/__init__.py +0 -0
  52. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/parsers/go.py +0 -0
  53. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/parsers/javascript.py +0 -0
  54. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/parsers/jvm.py +0 -0
  55. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/parsers/python.py +0 -0
  56. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/reports/__init__.py +0 -0
  57. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/reports/architecture.py +0 -0
  58. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre/rules.py +0 -0
  59. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre_cli.egg-info/dependency_links.txt +0 -0
  60. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre_cli.egg-info/entry_points.txt +0 -0
  61. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre_cli.egg-info/requires.txt +2 -2
  62. {adre_cli-0.2.0 → adre_cli-0.3.0}/adre_cli.egg-info/top_level.txt +0 -0
  63. {adre_cli-0.2.0 → adre_cli-0.3.0}/setup.cfg +0 -0
  64. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_accepted.py +0 -0
  65. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_architecture.py +0 -0
  66. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_ci_outputs.py +0 -0
  67. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_cycles.py +0 -0
  68. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_fail_on.py +0 -0
  69. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_file_limit.py +0 -0
  70. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_incremental.py +0 -0
  71. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_pr_comment.py +0 -0
  72. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_realistic.py +0 -0
  73. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_relationships.py +0 -0
  74. {adre_cli-0.2.0 → adre_cli-0.3.0}/tests/test_resolution.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: adre-cli
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Architecture Drift Review Engine: learn a repository's architecture and flag pull requests that drift from it.
5
5
  License: Apache-2.0
6
6
  Project-URL: Homepage, https://github.com/christiangebru/architect-reviewer
@@ -14,21 +14,41 @@ Classifier: Topic :: Software Development :: Quality Assurance
14
14
  Requires-Python: >=3.9
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
+ Requires-Dist: fastapi>=0.110
18
+ Requires-Dist: uvicorn>=0.27
17
19
  Provides-Extra: web
18
- Requires-Dist: fastapi>=0.110; extra == "web"
19
- Requires-Dist: uvicorn>=0.27; extra == "web"
20
20
  Dynamic: license-file
21
21
 
22
22
  # ADRE — Architecture Drift Review Engine
23
23
 
24
24
  **Zero-config architecture guardrails for pull requests.** ADRE learns the architecture your repository already follows, then fails a pull request only when *that pull request* breaks it: a controller reaching past the service layer into a repository, a reversed dependency, direct database access outside the persistence layer, a new import cycle.
25
25
 
26
- - **No rules to write.** Layers and dependency directions are inferred from the code and saved as a reviewable baseline. If you do want rules, declare them in `.adre/architecture.json`, and they are enforced even where inference finds nothing.
26
+ - **No rules to write, nothing to save.** Layers and dependency directions are learned from your main branch on every pull request. You can commit a baseline to pin them, but you don't have to. If you do want rules, declare them in `.adre/architecture.json`, and they are enforced even where inference finds nothing.
27
27
  - **Only new drift.** The PR head is compared with its base commit, renames included, so existing debt and unrelated files never fail a PR.
28
28
  - **Deterministic and explained.** Every finding names the changed import, the established path it breaks, the evidence and a confidence. No LLM in the loop.
29
29
  - **Built for CI.** One GitHub Action step, annotations on the offending line, SARIF for code scanning, JSON for everything else. The CLI has no dependencies.
30
30
  - **Python, JavaScript/TypeScript, Java, Kotlin and Go.**
31
31
 
32
+ ## Quick start
33
+
34
+ ```
35
+ pip install adre-cli
36
+ cd your-project
37
+ adre init # shows the architecture ADRE sees and adds the pull-request check
38
+ git add .github/workflows/architecture.yml && git commit -m "Add ADRE" && git push
39
+ ```
40
+
41
+ That's all. Every pull request now gets a check that fails on new architecture drift and one comment explaining each finding and how to fix it.
42
+
43
+ To look around on your own machine:
44
+
45
+ ```
46
+ adre ui # opens the web UI in your browser, on this project
47
+ adre review # checks your uncommitted changes
48
+ ```
49
+
50
+ On macOS with Homebrew's Python, `pip install` refuses to install into the system Python. Use a virtual environment: `python3 -m venv ~/.adre && ~/.adre/bin/pip install adre-cli`, then add `~/.adre/bin` to your `PATH`.
51
+
32
52
  ### How it compares
33
53
 
34
54
  | | Rules required | Gates PRs on new drift only | Indirect (chain) violations | Languages |
@@ -83,10 +103,11 @@ Unsupported languages are counted and skipped. Repository source is never execut
83
103
  ## Install
84
104
 
85
105
  ```
86
- pip install adre-cli # CLI only, no dependencies
87
- pip install "adre-cli[web]" # plus the local web UI
106
+ pip install adre-cli
88
107
  ```
89
108
 
109
+ This includes the web UI. The analysis engine itself uses only the Python standard library, which is why the GitHub Action needs no install step.
110
+
90
111
  To install an unreleased version from GitHub: `pip install "git+https://github.com/christiangebru/architect-reviewer@main"`.
91
112
 
92
113
  This installs the `adre` command (the package is `adre-cli` because `adre` is taken on PyPI). From a source checkout, `./bin/adre` runs the same CLI without installing anything.
@@ -100,28 +121,37 @@ adre analyze ./my-repository
100
121
  adre analyze ./my-repository --select src/controllers
101
122
  ```
102
123
 
103
- Save the accepted architecture:
124
+ Set up a repository (prints the architecture, writes `.github/workflows/architecture.yml`; `--baseline` also pins today's architecture):
104
125
 
105
126
  ```
106
- adre baseline ./my-repository
127
+ adre init
107
128
  ```
108
129
 
109
- This writes `.adre/baseline.json`. Commit that file on the default branch.
110
-
111
- Compare the current tree against a saved baseline:
130
+ Check your uncommitted changes. Without a saved baseline, ADRE learns the architecture from the last commit; with one, it compares against the baseline:
112
131
 
113
132
  ```
114
- adre review ./my-repository
133
+ adre review
115
134
  adre review ./my-repository --against .adre/baseline.json
116
135
  ```
117
136
 
118
- Start the local web UI (needs the `web` extra; binds to 127.0.0.1 by default):
137
+ Optionally pin today's architecture, so that drift merged later cannot quietly become the new normal:
119
138
 
120
139
  ```
121
- adre web --port 8000
140
+ adre baseline
122
141
  ```
123
142
 
124
- The web UI gives the same answers as the CLI: **Review against baseline** runs exactly what `adre review` runs (baseline, declared rules, accepted and stale exceptions), and **Review a branch** runs the same pull-request review as the GitHub Action for the checked-out branch against a base you choose. On either page, **Accept with reason** records an intentional crossing in `.adre/accepted.json` (commit it so CI accepts it too). New repositories get a **Get started** checklist on the dashboard: save the baseline, commit it, review, and add the GitHub Action. The **Rules** page edits `.adre/architecture.json` visually: it starts from the layers ADRE found, lets you reorder, rename and add layers, turn on strict layering and add forbidden dependencies, and previews which files each layer claims and which current dependencies would break the rules before you save.
143
+ This writes `.adre/baseline.json`. Commit that file on the default branch. A committed baseline is also required outside git.
144
+
145
+ Open the web UI (opens your browser on this project's dashboard; picks a free port if 8000 is taken; binds to 127.0.0.1):
146
+
147
+ ```
148
+ adre ui
149
+ adre ui ./my-repository --port 9000 --no-browser
150
+ ```
151
+
152
+ `adre web` is the same command.
153
+
154
+ The web UI gives the same answers as the CLI: **Review against baseline** runs exactly what `adre review` runs (baseline, declared rules, accepted and stale exceptions), and **Review a branch** runs the same pull-request review as the GitHub Action for the checked-out branch against a base you choose. On either page, **Accept with reason** records an intentional crossing in `.adre/accepted.json` (commit it so CI accepts it too). New repositories get a **Get started** checklist on the dashboard: review your changes, review a branch, add the GitHub check, and optionally pin the architecture with a baseline. The **Rules** page edits `.adre/architecture.json` visually: it starts from the layers ADRE found, lets you reorder, rename and add layers, turn on strict layering and add forbidden dependencies, and previews which files each layer claims and which current dependencies would break the rules before you save.
125
155
 
126
156
  It only answers on localhost. Requests with another `Host` header or that the browser marks as cross-site are refused, and every action that changes something (saving a baseline, cloning or registering a repository, pinning, opening your editor) is a POST carrying a per-process token, so other websites cannot trigger them. Binding to another interface with `--host` prints a warning.
127
157
 
@@ -134,10 +164,10 @@ adre pr-check origin/main HEAD
134
164
 
135
165
  Statuses:
136
166
 
137
- - `PASS` (exit 0) — no new drift versus the accepted baseline
167
+ - `PASS` (exit 0) — no new drift
138
168
  - `DRIFT` (exit 2) — new architectural drift in the PR
139
169
  - `INCOMPLETE` (exit 4) — the PR changes a source file that was not analyzed because the project has more source files than the file limit (see below)
140
- - `BASELINE_REQUIRED` (exit 3) — no `.adre/baseline.json` on the base ref
170
+ - `BASELINE_REQUIRED` (exit 3) — the `--against` baseline file does not exist, or there is no saved baseline and the base branch could not be analyzed
141
171
  - `BASELINE_INVALID` (exit 1) — baseline could not be loaded
142
172
  - `ERROR` (exit 1) — git or analysis failure
143
173
 
@@ -145,7 +175,7 @@ Statuses:
145
175
 
146
176
  **File limit.** ADRE analyzes at most 5,000 source files by default, in a stable (sorted) order. When a project has more, every output says how many files were left out, and a pull request that changes one of them gets `INCOMPLETE` instead of `PASS`. Raise the limit with `--max-files N` (any command), the `ADRE_MAX_FILES` environment variable, or the action's `max-files` input; `0` means no limit.
147
177
 
148
- `pr-review` uses the baseline for the accepted architecture model (layers, directions, established paths), and analyzes the base commit in a throwaway clone to decide what is new. Only dependencies, cycles, and database imports that the PR adds relative to the base tree are reported. As a result:
178
+ `pr-review` uses `.adre/baseline.json` from the base commit as the accepted architecture model (layers, directions, established paths) when one is committed, and otherwise learns that model from the base commit itself. It always analyzes the base commit in a throwaway clone to decide what is new. Only dependencies, cycles, and database imports that the PR adds relative to the base tree are reported. As a result:
149
179
 
150
180
  - problems that already exist on the base branch are not blamed on the PR, even if they were merged after the baseline was saved
151
181
  - renamed or moved files (detected by `git diff -M`) do not count as new dependencies
@@ -174,12 +204,12 @@ jobs:
174
204
  - uses: actions/checkout@v4
175
205
  with:
176
206
  fetch-depth: 0 # the base commit and merge base must exist
177
- - uses: christiangebru/architect-reviewer@v0.2.0 # or @v0 for the latest 0.x, or a commit SHA
207
+ - uses: christiangebru/architect-reviewer@v0.3.0 # or @v0 for the latest 0.x, or a commit SHA
178
208
  with:
179
209
  path: . # project directory inside the repository
180
210
  ```
181
211
 
182
- The action compares the checked-out PR tree with the base commit, using `.adre/baseline.json` from the base commit as the accepted architecture, and fails the job on new drift. It writes the check summary to the job summary, adds an inline annotation on each finding (repository-relative paths, so projects in subdirectories work), and sets outputs `status`, `drift-count`, `warning-count`, `accepted-count` and `sarif-file`.
212
+ The action compares the checked-out PR tree with the base commit, using `.adre/baseline.json` from the base commit as the accepted architecture if one is committed (otherwise the architecture learned from the base commit), and fails the job on new drift. It writes the check summary to the job summary, adds an inline annotation on each finding (repository-relative paths, so projects in subdirectories work), and sets outputs `status`, `drift-count`, `warning-count`, `accepted-count` and `sarif-file`.
183
213
 
184
214
  | Input | Default | |
185
215
  |---|---|---|
@@ -199,7 +229,7 @@ The action compares the checked-out PR tree with the base commit, using `.adre/b
199
229
  To show findings in GitHub code scanning, write SARIF and upload it even when the check fails (needs `security-events: write`; private repositories need GitHub Advanced Security):
200
230
 
201
231
  ```yaml
202
- - uses: christiangebru/architect-reviewer@v0.2.0
232
+ - uses: christiangebru/architect-reviewer@v0.3.0
203
233
  id: adre
204
234
  with:
205
235
  sarif-file: adre.sarif
@@ -210,10 +240,10 @@ To show findings in GitHub code scanning, write SARIF and upload it even when th
210
240
  category: adre
211
241
  ```
212
242
 
213
- Commit a baseline on the default branch before relying on CI:
243
+ No baseline is needed: without one, the action learns the architecture from the base branch of each pull request. To pin today's architecture instead, commit a baseline on the default branch:
214
244
 
215
245
  ```
216
- adre baseline .
246
+ adre baseline
217
247
  git add .adre/baseline.json
218
248
  git commit -m "Save architecture baseline"
219
249
  ```
@@ -335,7 +365,7 @@ Unchanged files are reused from `.adre/parse-cache.json` by content hash. Change
335
365
  The CLI and engine use only the Python standard library (3.9+). All code lives in the `adre` package; FastAPI and Uvicorn are only needed for the optional web UI (`adre/web.py`, extra `web`).
336
366
 
337
367
  ```
338
- pip install -e ".[web]" # same as: pip install -r requirements.txt
368
+ pip install -e . # same as: pip install -r requirements.txt
339
369
  python3 -m unittest discover
340
370
  ```
341
371
 
@@ -2,12 +2,32 @@
2
2
 
3
3
  **Zero-config architecture guardrails for pull requests.** ADRE learns the architecture your repository already follows, then fails a pull request only when *that pull request* breaks it: a controller reaching past the service layer into a repository, a reversed dependency, direct database access outside the persistence layer, a new import cycle.
4
4
 
5
- - **No rules to write.** Layers and dependency directions are inferred from the code and saved as a reviewable baseline. If you do want rules, declare them in `.adre/architecture.json`, and they are enforced even where inference finds nothing.
5
+ - **No rules to write, nothing to save.** Layers and dependency directions are learned from your main branch on every pull request. You can commit a baseline to pin them, but you don't have to. If you do want rules, declare them in `.adre/architecture.json`, and they are enforced even where inference finds nothing.
6
6
  - **Only new drift.** The PR head is compared with its base commit, renames included, so existing debt and unrelated files never fail a PR.
7
7
  - **Deterministic and explained.** Every finding names the changed import, the established path it breaks, the evidence and a confidence. No LLM in the loop.
8
8
  - **Built for CI.** One GitHub Action step, annotations on the offending line, SARIF for code scanning, JSON for everything else. The CLI has no dependencies.
9
9
  - **Python, JavaScript/TypeScript, Java, Kotlin and Go.**
10
10
 
11
+ ## Quick start
12
+
13
+ ```
14
+ pip install adre-cli
15
+ cd your-project
16
+ adre init # shows the architecture ADRE sees and adds the pull-request check
17
+ git add .github/workflows/architecture.yml && git commit -m "Add ADRE" && git push
18
+ ```
19
+
20
+ That's all. Every pull request now gets a check that fails on new architecture drift and one comment explaining each finding and how to fix it.
21
+
22
+ To look around on your own machine:
23
+
24
+ ```
25
+ adre ui # opens the web UI in your browser, on this project
26
+ adre review # checks your uncommitted changes
27
+ ```
28
+
29
+ On macOS with Homebrew's Python, `pip install` refuses to install into the system Python. Use a virtual environment: `python3 -m venv ~/.adre && ~/.adre/bin/pip install adre-cli`, then add `~/.adre/bin` to your `PATH`.
30
+
11
31
  ### How it compares
12
32
 
13
33
  | | Rules required | Gates PRs on new drift only | Indirect (chain) violations | Languages |
@@ -62,10 +82,11 @@ Unsupported languages are counted and skipped. Repository source is never execut
62
82
  ## Install
63
83
 
64
84
  ```
65
- pip install adre-cli # CLI only, no dependencies
66
- pip install "adre-cli[web]" # plus the local web UI
85
+ pip install adre-cli
67
86
  ```
68
87
 
88
+ This includes the web UI. The analysis engine itself uses only the Python standard library, which is why the GitHub Action needs no install step.
89
+
69
90
  To install an unreleased version from GitHub: `pip install "git+https://github.com/christiangebru/architect-reviewer@main"`.
70
91
 
71
92
  This installs the `adre` command (the package is `adre-cli` because `adre` is taken on PyPI). From a source checkout, `./bin/adre` runs the same CLI without installing anything.
@@ -79,28 +100,37 @@ adre analyze ./my-repository
79
100
  adre analyze ./my-repository --select src/controllers
80
101
  ```
81
102
 
82
- Save the accepted architecture:
103
+ Set up a repository (prints the architecture, writes `.github/workflows/architecture.yml`; `--baseline` also pins today's architecture):
83
104
 
84
105
  ```
85
- adre baseline ./my-repository
106
+ adre init
86
107
  ```
87
108
 
88
- This writes `.adre/baseline.json`. Commit that file on the default branch.
89
-
90
- Compare the current tree against a saved baseline:
109
+ Check your uncommitted changes. Without a saved baseline, ADRE learns the architecture from the last commit; with one, it compares against the baseline:
91
110
 
92
111
  ```
93
- adre review ./my-repository
112
+ adre review
94
113
  adre review ./my-repository --against .adre/baseline.json
95
114
  ```
96
115
 
97
- Start the local web UI (needs the `web` extra; binds to 127.0.0.1 by default):
116
+ Optionally pin today's architecture, so that drift merged later cannot quietly become the new normal:
98
117
 
99
118
  ```
100
- adre web --port 8000
119
+ adre baseline
101
120
  ```
102
121
 
103
- The web UI gives the same answers as the CLI: **Review against baseline** runs exactly what `adre review` runs (baseline, declared rules, accepted and stale exceptions), and **Review a branch** runs the same pull-request review as the GitHub Action for the checked-out branch against a base you choose. On either page, **Accept with reason** records an intentional crossing in `.adre/accepted.json` (commit it so CI accepts it too). New repositories get a **Get started** checklist on the dashboard: save the baseline, commit it, review, and add the GitHub Action. The **Rules** page edits `.adre/architecture.json` visually: it starts from the layers ADRE found, lets you reorder, rename and add layers, turn on strict layering and add forbidden dependencies, and previews which files each layer claims and which current dependencies would break the rules before you save.
122
+ This writes `.adre/baseline.json`. Commit that file on the default branch. A committed baseline is also required outside git.
123
+
124
+ Open the web UI (opens your browser on this project's dashboard; picks a free port if 8000 is taken; binds to 127.0.0.1):
125
+
126
+ ```
127
+ adre ui
128
+ adre ui ./my-repository --port 9000 --no-browser
129
+ ```
130
+
131
+ `adre web` is the same command.
132
+
133
+ The web UI gives the same answers as the CLI: **Review against baseline** runs exactly what `adre review` runs (baseline, declared rules, accepted and stale exceptions), and **Review a branch** runs the same pull-request review as the GitHub Action for the checked-out branch against a base you choose. On either page, **Accept with reason** records an intentional crossing in `.adre/accepted.json` (commit it so CI accepts it too). New repositories get a **Get started** checklist on the dashboard: review your changes, review a branch, add the GitHub check, and optionally pin the architecture with a baseline. The **Rules** page edits `.adre/architecture.json` visually: it starts from the layers ADRE found, lets you reorder, rename and add layers, turn on strict layering and add forbidden dependencies, and previews which files each layer claims and which current dependencies would break the rules before you save.
104
134
 
105
135
  It only answers on localhost. Requests with another `Host` header or that the browser marks as cross-site are refused, and every action that changes something (saving a baseline, cloning or registering a repository, pinning, opening your editor) is a POST carrying a per-process token, so other websites cannot trigger them. Binding to another interface with `--host` prints a warning.
106
136
 
@@ -113,10 +143,10 @@ adre pr-check origin/main HEAD
113
143
 
114
144
  Statuses:
115
145
 
116
- - `PASS` (exit 0) — no new drift versus the accepted baseline
146
+ - `PASS` (exit 0) — no new drift
117
147
  - `DRIFT` (exit 2) — new architectural drift in the PR
118
148
  - `INCOMPLETE` (exit 4) — the PR changes a source file that was not analyzed because the project has more source files than the file limit (see below)
119
- - `BASELINE_REQUIRED` (exit 3) — no `.adre/baseline.json` on the base ref
149
+ - `BASELINE_REQUIRED` (exit 3) — the `--against` baseline file does not exist, or there is no saved baseline and the base branch could not be analyzed
120
150
  - `BASELINE_INVALID` (exit 1) — baseline could not be loaded
121
151
  - `ERROR` (exit 1) — git or analysis failure
122
152
 
@@ -124,7 +154,7 @@ Statuses:
124
154
 
125
155
  **File limit.** ADRE analyzes at most 5,000 source files by default, in a stable (sorted) order. When a project has more, every output says how many files were left out, and a pull request that changes one of them gets `INCOMPLETE` instead of `PASS`. Raise the limit with `--max-files N` (any command), the `ADRE_MAX_FILES` environment variable, or the action's `max-files` input; `0` means no limit.
126
156
 
127
- `pr-review` uses the baseline for the accepted architecture model (layers, directions, established paths), and analyzes the base commit in a throwaway clone to decide what is new. Only dependencies, cycles, and database imports that the PR adds relative to the base tree are reported. As a result:
157
+ `pr-review` uses `.adre/baseline.json` from the base commit as the accepted architecture model (layers, directions, established paths) when one is committed, and otherwise learns that model from the base commit itself. It always analyzes the base commit in a throwaway clone to decide what is new. Only dependencies, cycles, and database imports that the PR adds relative to the base tree are reported. As a result:
128
158
 
129
159
  - problems that already exist on the base branch are not blamed on the PR, even if they were merged after the baseline was saved
130
160
  - renamed or moved files (detected by `git diff -M`) do not count as new dependencies
@@ -153,12 +183,12 @@ jobs:
153
183
  - uses: actions/checkout@v4
154
184
  with:
155
185
  fetch-depth: 0 # the base commit and merge base must exist
156
- - uses: christiangebru/architect-reviewer@v0.2.0 # or @v0 for the latest 0.x, or a commit SHA
186
+ - uses: christiangebru/architect-reviewer@v0.3.0 # or @v0 for the latest 0.x, or a commit SHA
157
187
  with:
158
188
  path: . # project directory inside the repository
159
189
  ```
160
190
 
161
- The action compares the checked-out PR tree with the base commit, using `.adre/baseline.json` from the base commit as the accepted architecture, and fails the job on new drift. It writes the check summary to the job summary, adds an inline annotation on each finding (repository-relative paths, so projects in subdirectories work), and sets outputs `status`, `drift-count`, `warning-count`, `accepted-count` and `sarif-file`.
191
+ The action compares the checked-out PR tree with the base commit, using `.adre/baseline.json` from the base commit as the accepted architecture if one is committed (otherwise the architecture learned from the base commit), and fails the job on new drift. It writes the check summary to the job summary, adds an inline annotation on each finding (repository-relative paths, so projects in subdirectories work), and sets outputs `status`, `drift-count`, `warning-count`, `accepted-count` and `sarif-file`.
162
192
 
163
193
  | Input | Default | |
164
194
  |---|---|---|
@@ -178,7 +208,7 @@ The action compares the checked-out PR tree with the base commit, using `.adre/b
178
208
  To show findings in GitHub code scanning, write SARIF and upload it even when the check fails (needs `security-events: write`; private repositories need GitHub Advanced Security):
179
209
 
180
210
  ```yaml
181
- - uses: christiangebru/architect-reviewer@v0.2.0
211
+ - uses: christiangebru/architect-reviewer@v0.3.0
182
212
  id: adre
183
213
  with:
184
214
  sarif-file: adre.sarif
@@ -189,10 +219,10 @@ To show findings in GitHub code scanning, write SARIF and upload it even when th
189
219
  category: adre
190
220
  ```
191
221
 
192
- Commit a baseline on the default branch before relying on CI:
222
+ No baseline is needed: without one, the action learns the architecture from the base branch of each pull request. To pin today's architecture instead, commit a baseline on the default branch:
193
223
 
194
224
  ```
195
- adre baseline .
225
+ adre baseline
196
226
  git add .adre/baseline.json
197
227
  git commit -m "Save architecture baseline"
198
228
  ```
@@ -314,7 +344,7 @@ Unchanged files are reused from `.adre/parse-cache.json` by content hash. Change
314
344
  The CLI and engine use only the Python standard library (3.9+). All code lives in the `adre` package; FastAPI and Uvicorn are only needed for the optional web UI (`adre/web.py`, extra `web`).
315
345
 
316
346
  ```
317
- pip install -e ".[web]" # same as: pip install -r requirements.txt
347
+ pip install -e . # same as: pip install -r requirements.txt
318
348
  python3 -m unittest discover
319
349
  ```
320
350
 
@@ -2,4 +2,4 @@
2
2
 
3
3
  # Release version of the package. ANALYZER_VERSION in adre.core.config is
4
4
  # separate: it changes when analysis results change and invalidates caches.
5
- __version__ = "0.2.0"
5
+ __version__ = "0.3.0"
@@ -25,6 +25,7 @@ from adre.core.git_intelligence import (
25
25
  from adre.core.review import review_working_tree
26
26
  from adre.core.github_check import format_github_check, write_github_output, write_step_outputs
27
27
  from adre.core.sarif import write_sarif
28
+ from adre.core.setup import git_prefix, git_root, write_workflow
28
29
  from adre.core.pr_comment import PRCommentError, comment_context, format_pr_comment, publish_pr_comment
29
30
  from adre.core.pr_review import exit_code_for, review_pull_request
30
31
  from adre.core.snapshots import compare_snapshot_data, load_snapshot_file, snapshot_from_analysis
@@ -130,7 +131,11 @@ def print_architecture(baseline):
130
131
 
131
132
  def print_review(comparison):
132
133
  print_header("Architecture Review")
133
- print("Comparing current analysis against the saved baseline.")
134
+ if comparison.get("baseline_inferred_from"):
135
+ print("No saved baseline: comparing uncommitted changes with the architecture of the last commit.")
136
+ print("Run `adre baseline .` and commit .adre/baseline.json to pin today's architecture.")
137
+ else:
138
+ print("Comparing current analysis against the saved baseline.")
134
139
  print(comparison.get("summary") or "No comparison summary.")
135
140
  if (comparison.get("truncation") or {}).get("message"):
136
141
  print("Warning: {0}".format(comparison["truncation"]["message"]))
@@ -808,14 +813,44 @@ def command_explain(args):
808
813
  return 0
809
814
 
810
815
 
811
- def command_web(args):
816
+ DEFAULT_UI_PORT = 8000
817
+
818
+
819
+ def free_port(host, preferred):
820
+ """`preferred` if it is free on `host`, otherwise any free port."""
821
+ import socket
822
+
823
+ family = socket.AF_INET6 if ":" in host else socket.AF_INET
824
+ for port in (preferred, 0):
825
+ with socket.socket(family, socket.SOCK_STREAM) as probe:
826
+ try:
827
+ probe.bind((host, port))
828
+ except OSError:
829
+ continue
830
+ return probe.getsockname()[1]
831
+ return preferred
832
+
833
+
834
+ def ui_start_url(host, port, project_path):
835
+ """Open straight on the project's dashboard when it has source code."""
836
+ from urllib.parse import quote
837
+
838
+ from adre.core.repositories import has_source_files
839
+
840
+ display_host = "127.0.0.1" if host in {"0.0.0.0", "::"} else ("[{0}]".format(host) if ":" in host else host)
841
+ base = "http://{0}:{1}".format(display_host, port)
842
+ if project_path and os.path.isdir(project_path) and has_source_files(project_path):
843
+ return "{0}/dashboard?path={1}".format(base, quote(os.path.realpath(project_path)))
844
+ return base + "/"
845
+
846
+
847
+ def command_ui(args):
812
848
  try:
813
849
  import uvicorn
814
850
  from adre.web import app
815
851
  except ImportError as exc:
816
852
  print(
817
- "Error: the web UI needs optional dependencies ({0}). "
818
- "Install them with: pip install 'adre-cli[web]'".format(exc.name or exc),
853
+ "Error: the web UI could not load ({0}). Reinstall ADRE with: pip install --upgrade adre-cli".format(exc.name or exc),
819
854
  file=sys.stderr,
820
855
  )
821
856
  return 1
@@ -830,22 +865,105 @@ def command_web(args):
830
865
  # Let requests addressed to that host name through the Host check.
831
866
  existing = os.environ.get("ADRE_WEB_ALLOWED_HOSTS", "")
832
867
  os.environ["ADRE_WEB_ALLOWED_HOSTS"] = ",".join(item for item in (existing, host) if item)
833
- uvicorn.run(app, host=host, port=args.port)
868
+ port = args.port if args.port is not None else free_port(host, DEFAULT_UI_PORT)
869
+ url = ui_start_url(host, port, getattr(args, "path", None) or ".")
870
+ print("ADRE is running at {0}".format(url), flush=True)
871
+ print("Press Ctrl+C to stop.", flush=True)
872
+ if not args.no_browser:
873
+ import threading
874
+ import webbrowser
875
+
876
+ threading.Timer(1.0, webbrowser.open, args=(url,)).start()
877
+ uvicorn.run(app, host=host, port=port, log_level="warning")
878
+ return 0
879
+
880
+
881
+ command_web = command_ui
882
+
883
+
884
+ def command_init(args):
885
+ project_path = os.path.realpath(args.path)
886
+ if not os.path.isdir(project_path):
887
+ print("Error: {0} is not a folder.".format(args.path), file=sys.stderr)
888
+ return 1
889
+ analysis = analyze_project_architecture(project_path)
890
+ architecture = analysis.get("architecture") or {}
891
+ scope = analysis.get("scope") or {}
892
+ print_header("ADRE setup")
893
+ print("Project: {0}".format(project_path))
894
+ languages = scope.get("languages") or {}
895
+ print("Source files: {0}{1}".format(
896
+ scope.get("analyzed_file_count", 0),
897
+ " ({0})".format(", ".join("{0} {1}".format(name, count) for name, count in sorted(languages.items()))) if languages else "",
898
+ ))
899
+ if architecture.get("enough_structure") and architecture.get("summary_path"):
900
+ print("ADRE sees this architecture: {0}".format(architecture["summary_path"]))
901
+ else:
902
+ print("ADRE found no clear layers yet. New import cycles are still checked, and you can declare")
903
+ print("the layers you want with `adre ui` (Rules page) or .adre/architecture.json.")
904
+ if not scope.get("analyzed_file_count"):
905
+ print("\nNo Python, JavaScript/TypeScript, Java, Kotlin or Go files were found here.")
906
+ return 1
907
+
908
+ prefix = git_prefix(project_path)
909
+ if prefix is None:
910
+ print("\nThis folder is not a git repository, so there is no pull-request check to add.")
911
+ print("Save a snapshot to compare against later: adre baseline .")
912
+ print("See it visually: adre ui")
913
+ return 0
914
+
915
+ to_add = []
916
+ workflow_file, state = write_workflow(project_path, force=args.force)
917
+ repo_root = git_root(project_path) or project_path
918
+ rel_workflow = os.path.relpath(workflow_file, repo_root)
919
+ if state == "exists":
920
+ print("\n{0} already exists; left unchanged (use --force to replace it).".format(rel_workflow))
921
+ else:
922
+ print("\n{0} {1}: every pull request gets the ADRE check and one".format(
923
+ "Created" if state == "created" else "Replaced", rel_workflow))
924
+ print("comment explaining any drift. No baseline is needed: ADRE learns the architecture from your main branch.")
925
+ to_add.append(rel_workflow)
926
+ if args.baseline:
927
+ destination = save_architecture_baseline(architecture)
928
+ rel_baseline = os.path.relpath(destination, repo_root)
929
+ print("Saved {0} to pin today's architecture.".format(rel_baseline))
930
+ to_add.append(rel_baseline)
931
+
932
+ print("\nNext:")
933
+ if to_add:
934
+ print(" git add {0}".format(" ".join(to_add)))
935
+ print(' git commit -m "Add ADRE architecture check"')
936
+ print(" git push")
937
+ print(" adre ui # see the architecture and review changes in your browser")
834
938
  return 0
835
939
 
836
940
 
941
+ GETTING_STARTED = """getting started:
942
+ adre init set up the pull-request check in this repository
943
+ adre ui open the web UI on this project
944
+ adre review check your uncommitted changes
945
+ adre pr-review main check this branch the way the pull-request check does
946
+
947
+ All commands: adre <command> --help"""
948
+
949
+
837
950
  def build_parser():
838
- parser = argparse.ArgumentParser(prog="adre", description="ADRE CLI")
951
+ parser = argparse.ArgumentParser(
952
+ prog="adre",
953
+ description="ADRE: catch architecture drift before it is merged.",
954
+ formatter_class=argparse.RawDescriptionHelpFormatter,
955
+ epilog=GETTING_STARTED,
956
+ )
839
957
  parser.add_argument(
840
958
  "--version",
841
959
  action="version",
842
960
  version="%(prog)s {0} (analyzer {1})".format(__version__, ANALYZER_VERSION),
843
961
  )
844
- subparsers = parser.add_subparsers(dest="command", required=True)
962
+ subparsers = parser.add_subparsers(dest="command", metavar="<command>", title="commands")
845
963
 
846
964
  analyze_parser = subparsers.add_parser("analyze", help="Analyze current code. Does not update the saved baseline.")
847
965
  add_max_files_argument(analyze_parser)
848
- analyze_parser.add_argument("path")
966
+ analyze_parser.add_argument("path", nargs="?", default=".", help="Project folder (default: current folder)")
849
967
  analyze_parser.add_argument(
850
968
  "--select",
851
969
  nargs="+",
@@ -861,7 +979,7 @@ def build_parser():
861
979
 
862
980
  baseline_parser = subparsers.add_parser("baseline", help="Save the current architecture as the accepted baseline")
863
981
  add_max_files_argument(baseline_parser)
864
- baseline_parser.add_argument("path")
982
+ baseline_parser.add_argument("path", nargs="?", default=".", help="Project folder (default: current folder)")
865
983
  baseline_parser.add_argument("--select", nargs="+", default=None)
866
984
  baseline_parser.add_argument("--no-expand", action="store_true")
867
985
  baseline_parser.add_argument("--output", help="Baseline JSON path (default: <project>/.adre/baseline.json)")
@@ -870,7 +988,7 @@ def build_parser():
870
988
  review_parser = subparsers.add_parser("review", help="Compare current analysis against a saved architecture baseline")
871
989
  add_max_files_argument(review_parser)
872
990
  add_fail_on_argument(review_parser)
873
- review_parser.add_argument("path")
991
+ review_parser.add_argument("path", nargs="?", default=".", help="Project folder (default: current folder)")
874
992
  review_parser.add_argument("--select", nargs="+", default=None)
875
993
  review_parser.add_argument("--no-expand", action="store_true")
876
994
  review_parser.add_argument("--against", help="Baseline JSON path (default: <project>/.adre/baseline.json)")
@@ -878,7 +996,7 @@ def build_parser():
878
996
 
879
997
  report_parser = subparsers.add_parser("report", help="Print a terminal architecture report")
880
998
  add_max_files_argument(report_parser)
881
- report_parser.add_argument("path")
999
+ report_parser.add_argument("path", nargs="?", default=".", help="Project folder (default: current folder)")
882
1000
  report_parser.add_argument("--select", nargs="+", default=None)
883
1001
  report_parser.add_argument("--no-expand", action="store_true")
884
1002
  report_parser.set_defaults(func=command_report)
@@ -957,12 +1075,27 @@ def build_parser():
957
1075
  pr_review_parser.add_argument("--comment-file", metavar="PATH", help="Also write the PR comment markdown to PATH")
958
1076
  pr_review_parser.set_defaults(func=command_pr_check)
959
1077
 
960
- web_parser = subparsers.add_parser("web", help="Start the local web UI (needs: pip install 'adre-cli[web]')")
961
- add_max_files_argument(web_parser)
962
- add_fail_on_argument(web_parser)
963
- web_parser.add_argument("--host", default="127.0.0.1", help="Interface to bind (default: 127.0.0.1, local only)")
964
- web_parser.add_argument("--port", type=int, default=8000)
965
- web_parser.set_defaults(func=command_web)
1078
+ for name, help_text in (
1079
+ ("ui", "Open the web UI in your browser, on this project's dashboard"),
1080
+ ("web", "Same as ui"),
1081
+ ):
1082
+ ui_parser = subparsers.add_parser(name, help=help_text)
1083
+ ui_parser.add_argument("path", nargs="?", default=".", help="Project to open (default: current folder)")
1084
+ add_max_files_argument(ui_parser)
1085
+ add_fail_on_argument(ui_parser)
1086
+ ui_parser.add_argument("--host", default="127.0.0.1", help="Interface to bind (default: 127.0.0.1, local only)")
1087
+ ui_parser.add_argument("--port", type=int, default=None, help="Port (default: 8000, or a free one if 8000 is taken)")
1088
+ ui_parser.add_argument("--no-browser", action="store_true", help="Do not open a browser window")
1089
+ ui_parser.set_defaults(func=command_ui)
1090
+
1091
+ init_parser = subparsers.add_parser(
1092
+ "init", help="Set up ADRE in a repository: show the architecture and add the pull-request check"
1093
+ )
1094
+ init_parser.add_argument("path", nargs="?", default=".", help="Project folder (default: current folder)")
1095
+ init_parser.add_argument("--force", action="store_true", help="Replace an existing .github/workflows/architecture.yml")
1096
+ init_parser.add_argument("--baseline", action="store_true", help="Also save .adre/baseline.json to pin today's architecture")
1097
+ add_max_files_argument(init_parser)
1098
+ init_parser.set_defaults(func=command_init)
966
1099
 
967
1100
  return parser
968
1101
 
@@ -992,6 +1125,9 @@ def add_fail_on_argument(parser):
992
1125
  def main(argv=None):
993
1126
  parser = build_parser()
994
1127
  args = parser.parse_args(argv)
1128
+ if not getattr(args, "func", None):
1129
+ parser.print_help()
1130
+ return 0
995
1131
  max_files = getattr(args, "max_files", None)
996
1132
  if max_files is not None and max_files < 0:
997
1133
  print("Error: --max-files must be 0 (no limit) or a positive number.", file=sys.stderr)
@@ -75,6 +75,12 @@ def _truncation_lines(result):
75
75
  return lines
76
76
 
77
77
 
78
+ def baseline_note(result):
79
+ if result.get("baseline_source") == "inferred_from_base":
80
+ return " (learned from the base branch; commit `.adre/baseline.json` with `adre baseline .` to pin it)"
81
+ return ""
82
+
83
+
78
84
  def format_github_check(result):
79
85
  status = result.get("status") or ERROR
80
86
  drift = result.get("drift") or []
@@ -87,7 +93,7 @@ def format_github_check(result):
87
93
  "",
88
94
  result.get("summary") or "No new architectural drift detected.",
89
95
  "",
90
- "Established architecture: `{0}`".format(established),
96
+ "Established architecture: `{0}`{1}".format(established, baseline_note(result)),
91
97
  ])
92
98
  lines.extend(_warning_lines(result))
93
99
  lines.extend(_truncation_lines(result))
@@ -136,7 +142,7 @@ def format_github_check(result):
136
142
  "",
137
143
  "{0} new architectural drift".format(len(drift)) if drift else (result.get("summary") or ""),
138
144
  "",
139
- "Established architecture: `{0}`".format(established),
145
+ "Established architecture: `{0}`{1}".format(established, baseline_note(result)),
140
146
  "",
141
147
  ])
142
148
  for index, item in enumerate(drift, start=1):