impact-gate 0.1.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 (40) hide show
  1. impact_gate-0.1.0/LICENSE +201 -0
  2. impact_gate-0.1.0/PKG-INFO +194 -0
  3. impact_gate-0.1.0/README.md +164 -0
  4. impact_gate-0.1.0/impact_gate/__init__.py +8 -0
  5. impact_gate-0.1.0/impact_gate/baseline.py +208 -0
  6. impact_gate-0.1.0/impact_gate/cli.py +201 -0
  7. impact_gate-0.1.0/impact_gate/config.py +123 -0
  8. impact_gate-0.1.0/impact_gate/core/__init__.py +10 -0
  9. impact_gate-0.1.0/impact_gate/core/config.py +102 -0
  10. impact_gate-0.1.0/impact_gate/core/gitplumb.py +153 -0
  11. impact_gate-0.1.0/impact_gate/core/impact.py +164 -0
  12. impact_gate-0.1.0/impact_gate/core/lizard_plugin.py +47 -0
  13. impact_gate-0.1.0/impact_gate/core/units.py +42 -0
  14. impact_gate-0.1.0/impact_gate/data/__init__.py +108 -0
  15. impact_gate-0.1.0/impact_gate/data/defaults.json +31 -0
  16. impact_gate-0.1.0/impact_gate/data/seed_percentiles.json +120 -0
  17. impact_gate-0.1.0/impact_gate/engine.py +122 -0
  18. impact_gate-0.1.0/impact_gate/ghapi.py +94 -0
  19. impact_gate-0.1.0/impact_gate/gitio.py +189 -0
  20. impact_gate-0.1.0/impact_gate/providers.py +163 -0
  21. impact_gate-0.1.0/impact_gate/report.py +173 -0
  22. impact_gate-0.1.0/impact_gate.egg-info/PKG-INFO +194 -0
  23. impact_gate-0.1.0/impact_gate.egg-info/SOURCES.txt +38 -0
  24. impact_gate-0.1.0/impact_gate.egg-info/dependency_links.txt +1 -0
  25. impact_gate-0.1.0/impact_gate.egg-info/entry_points.txt +2 -0
  26. impact_gate-0.1.0/impact_gate.egg-info/requires.txt +5 -0
  27. impact_gate-0.1.0/impact_gate.egg-info/top_level.txt +1 -0
  28. impact_gate-0.1.0/pyproject.toml +66 -0
  29. impact_gate-0.1.0/setup.cfg +4 -0
  30. impact_gate-0.1.0/tests/test_baseline.py +121 -0
  31. impact_gate-0.1.0/tests/test_behavior.py +22 -0
  32. impact_gate-0.1.0/tests/test_cli.py +173 -0
  33. impact_gate-0.1.0/tests/test_config.py +27 -0
  34. impact_gate-0.1.0/tests/test_data.py +83 -0
  35. impact_gate-0.1.0/tests/test_ghapi.py +57 -0
  36. impact_gate-0.1.0/tests/test_gitio.py +49 -0
  37. impact_gate-0.1.0/tests/test_java_annotations.py +72 -0
  38. impact_gate-0.1.0/tests/test_measure.py +69 -0
  39. impact_gate-0.1.0/tests/test_providers.py +90 -0
  40. impact_gate-0.1.0/tests/test_report.py +77 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.4
2
+ Name: impact-gate
3
+ Version: 0.1.0
4
+ Summary: Measure and gate structural decay from a change (standalone + CI plugin).
5
+ Author: Daniel Sagenschneider
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/officefloor/ImpactGate
8
+ Project-URL: Repository, https://github.com/officefloor/ImpactGate
9
+ Project-URL: Issues, https://github.com/officefloor/ImpactGate/issues
10
+ Keywords: code-quality,complexity,static-analysis,ci,pre-commit,technical-debt,maintainability,code-review
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Quality Assurance
21
+ Classifier: Topic :: Software Development :: Version Control :: Git
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: lizard!=1.24.0,>=1.17
26
+ Requires-Dist: PyYAML>=6
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # impact-gate
32
+
33
+ Measure and gate the structural decay a change introduces. Run it as a standalone CLI,
34
+ a git pre-commit hook, or a plugin in GitHub, GitLab, and Jenkins CI.
35
+
36
+ Structural decay is complexity accreting into existing structures. A god-method grows
37
+ another branch. A god-class gains another method. The gate scores a change against a
38
+ base (`main` by default) with the change-impact measure:
39
+
40
+ ```
41
+ impact = files_changed * Σ max(WMC_other, 1) * CC * Δlines (over changed functions)
42
+ ```
43
+
44
+ `WMC_other` is the complexity already in the container you are editing. It is measured
45
+ on the pre-change state. So importing a brand-new file or class is cheap. Nothing was
46
+ there before. Piling onto an already-heavy class is expensive. That is the decay signal.
47
+
48
+ When impact is too high, the gate asks you to simplify the change or refactor the code
49
+ it touches. It can warn (report only) or block (fail the build).
50
+
51
+ This tool is the instrument for an experiment. The experiment studies how to control
52
+ structural decay under AI-augmented development. The gate sits in front of every change,
53
+ human or AI, so complexity cannot silently concentrate.
54
+
55
+ > Fully standalone. The measure is vendored in `impact_gate/core/`. Only `lizard` is
56
+ > required at runtime.
57
+
58
+ ## Install
59
+
60
+ ```bash
61
+ pip install impact-gate # installs the `impact-gate` command
62
+ ```
63
+
64
+ Or run it without installing anything, via the published image (git is bundled;
65
+ mount the repo to score at `/repo`):
66
+
67
+ ```bash
68
+ docker run --rm -v "$PWD:/repo" ghcr.io/officefloor/impact-gate \
69
+ score --mode range --base origin/main
70
+ ```
71
+
72
+ To hack on it locally, install from a checkout instead:
73
+
74
+ ```bash
75
+ python -m venv .venv && . .venv/bin/activate
76
+ pip install -e '.[dev]' # editable install plus the test deps
77
+ ```
78
+
79
+ ## Use
80
+
81
+ ```bash
82
+ # The commit you are about to make (pre-commit): staged vs HEAD. This is the default.
83
+ impact-gate score
84
+
85
+ # Uncommitted local edits: working tree vs HEAD.
86
+ impact-gate score --mode worktree
87
+
88
+ # CI or PR review: the committed branch vs main (merge-base..HEAD).
89
+ impact-gate score --mode range --base origin/main --format json
90
+
91
+ # Set thresholds and enforcement. You can also put these in .impact-gate.yml.
92
+ impact-gate score --warn-at 50000 --block-at 200000 --enforcement block
93
+ ```
94
+
95
+ Exit codes. `0` means ok or warn (the change is allowed). `2` means blocked (impact too
96
+ high under `--enforcement block`). `1` means a usage or environment error.
97
+
98
+ Every report also lists the **files to consider for refactoring**, ranked by their share
99
+ of the impact. The change-level number gates; the per-file ranking points at where the
100
+ decay is concentrating, so a file quietly growing into a god-class surfaces as a
101
+ candidate before it blocks anything.
102
+
103
+ ## Grade against a distribution (the curve)
104
+
105
+ A raw threshold is hard to set: a typical change's impact varies by orders of magnitude
106
+ across languages and projects. Instead of guessing a number, grade a change by its
107
+ **percentile** against a distribution, and gate on the percentile.
108
+
109
+ ```bash
110
+ # Build (or refresh) the project's own impact distribution from the merged history.
111
+ # Writes .impact-gate-baseline.json. Re-run it as the branch moves.
112
+ impact-gate baseline --base-ref main
113
+
114
+ # Gate on the grade instead of an absolute number.
115
+ impact-gate score --curve --warn-percentile 90 --block-percentile 98
116
+ ```
117
+
118
+ The grade blends two distributions:
119
+
120
+ - a **seed prior** shipped with the tool — per-language percentile tables built from a
121
+ 20-repo open-source corpus, with a pooled fallback for languages not in the table;
122
+ - the **project baseline** — the repo's own per-change distribution, walked from the
123
+ merged mainline (only landed work; in-flight branches are never reached).
124
+
125
+ The blend weights the project by `w = n / (n + K)`, where `n` is the number of landed
126
+ changes behind the baseline and `K` (`curve_prior_weight`, default 200) is how much
127
+ history it takes to trust the project over the seed. A fresh repo with no baseline file
128
+ grades on the seed alone; a deep history leans on itself. The grade shows in every
129
+ format next to the raw number.
130
+
131
+ ## Configure with `.impact-gate.yml` (repo root)
132
+
133
+ ```yaml
134
+ warn_at: 50000 # impact above which to warn
135
+ block_at: 200000 # impact above which to block
136
+ enforcement: warn # off, warn, or block. Start on warn. Flip to block when ready.
137
+ tolerance: 1.0 # CI-adjustable multiplier on both thresholds. Above 1 is more lenient.
138
+ # measure_config: .impact-measure.yml # optional: ignore globs and language overrides
139
+
140
+ # Grading curve (percentile gate). When enabled, warn_at/block_at are ignored and the
141
+ # gate uses the percentiles below instead.
142
+ curve_enabled: false # gate on the percentile grade instead of absolute numbers
143
+ warn_percentile: 90 # grade at or above this warns
144
+ block_percentile: 98 # grade at or above this blocks
145
+ curve_prior_weight: 200 # K in w = n/(n+K): history needed to trust the project over the seed
146
+ baseline_file: .impact-gate-baseline.json # where `impact-gate baseline` caches the distribution
147
+ ```
148
+
149
+ CLI flags override the file. A CI job can pass `--tolerance` or `--warn-at`. So a team
150
+ can dial tolerance without editing the repo. The curve knobs have flags too: `--curve`,
151
+ `--warn-percentile`, `--block-percentile`, `--baseline-file`.
152
+
153
+ ## Use in GitHub Actions
154
+
155
+ Add a workflow to your repo. The action scores the PR branch against its base and writes
156
+ a summary. `fetch-depth: 0` is required so the base branch and merge-base are present.
157
+
158
+ ```yaml
159
+ name: Change impact
160
+ on: pull_request
161
+ permissions:
162
+ contents: read
163
+ pull-requests: write # so the action can post the score as a PR comment
164
+ jobs:
165
+ impact:
166
+ runs-on: ubuntu-latest
167
+ steps:
168
+ - uses: actions/checkout@v5
169
+ with:
170
+ fetch-depth: 0
171
+ - uses: officefloor/ImpactGate@v1
172
+ with:
173
+ enforcement: warn # switch to block when ready
174
+ # warn-at: 50000
175
+ # block-at: 200000
176
+ # tolerance: 1.0
177
+ ```
178
+
179
+ The score appears in the job summary and as a sticky comment on the PR (one comment,
180
+ updated each run). In `block` mode the job fails when impact exceeds the block threshold.
181
+ Make the check required in branch protection to gate merges. The comment needs
182
+ `pull-requests: write`. Without it the run still passes and just skips the comment.
183
+
184
+ ## Roadmap
185
+
186
+ - Core CLI. Score staged, worktree, or range. Warn or block. Text, JSON, markdown. Done.
187
+ - GitHub Action. Composite action, job-summary report, and a sticky PR comment. Done.
188
+ - Baseline and grading curve. `impact-gate baseline` profiles the project history; the
189
+ gate blends a seed-corpus prior with the project's own distribution and grades a change
190
+ by its percentile (`score --curve`). Done.
191
+ - Distribution. `pip install impact-gate`, a `ghcr.io/officefloor/impact-gate` Docker
192
+ image for any CI, and a version-tagged Action (`@v0`). Done.
193
+ - More CI plugins. A GitLab CI template and a Jenkins shared library.
194
+ - Hooks and IDE. An `impact-gate install-hook` for pre-commit. Editor integration over LSP.
@@ -0,0 +1,164 @@
1
+ # impact-gate
2
+
3
+ Measure and gate the structural decay a change introduces. Run it as a standalone CLI,
4
+ a git pre-commit hook, or a plugin in GitHub, GitLab, and Jenkins CI.
5
+
6
+ Structural decay is complexity accreting into existing structures. A god-method grows
7
+ another branch. A god-class gains another method. The gate scores a change against a
8
+ base (`main` by default) with the change-impact measure:
9
+
10
+ ```
11
+ impact = files_changed * Σ max(WMC_other, 1) * CC * Δlines (over changed functions)
12
+ ```
13
+
14
+ `WMC_other` is the complexity already in the container you are editing. It is measured
15
+ on the pre-change state. So importing a brand-new file or class is cheap. Nothing was
16
+ there before. Piling onto an already-heavy class is expensive. That is the decay signal.
17
+
18
+ When impact is too high, the gate asks you to simplify the change or refactor the code
19
+ it touches. It can warn (report only) or block (fail the build).
20
+
21
+ This tool is the instrument for an experiment. The experiment studies how to control
22
+ structural decay under AI-augmented development. The gate sits in front of every change,
23
+ human or AI, so complexity cannot silently concentrate.
24
+
25
+ > Fully standalone. The measure is vendored in `impact_gate/core/`. Only `lizard` is
26
+ > required at runtime.
27
+
28
+ ## Install
29
+
30
+ ```bash
31
+ pip install impact-gate # installs the `impact-gate` command
32
+ ```
33
+
34
+ Or run it without installing anything, via the published image (git is bundled;
35
+ mount the repo to score at `/repo`):
36
+
37
+ ```bash
38
+ docker run --rm -v "$PWD:/repo" ghcr.io/officefloor/impact-gate \
39
+ score --mode range --base origin/main
40
+ ```
41
+
42
+ To hack on it locally, install from a checkout instead:
43
+
44
+ ```bash
45
+ python -m venv .venv && . .venv/bin/activate
46
+ pip install -e '.[dev]' # editable install plus the test deps
47
+ ```
48
+
49
+ ## Use
50
+
51
+ ```bash
52
+ # The commit you are about to make (pre-commit): staged vs HEAD. This is the default.
53
+ impact-gate score
54
+
55
+ # Uncommitted local edits: working tree vs HEAD.
56
+ impact-gate score --mode worktree
57
+
58
+ # CI or PR review: the committed branch vs main (merge-base..HEAD).
59
+ impact-gate score --mode range --base origin/main --format json
60
+
61
+ # Set thresholds and enforcement. You can also put these in .impact-gate.yml.
62
+ impact-gate score --warn-at 50000 --block-at 200000 --enforcement block
63
+ ```
64
+
65
+ Exit codes. `0` means ok or warn (the change is allowed). `2` means blocked (impact too
66
+ high under `--enforcement block`). `1` means a usage or environment error.
67
+
68
+ Every report also lists the **files to consider for refactoring**, ranked by their share
69
+ of the impact. The change-level number gates; the per-file ranking points at where the
70
+ decay is concentrating, so a file quietly growing into a god-class surfaces as a
71
+ candidate before it blocks anything.
72
+
73
+ ## Grade against a distribution (the curve)
74
+
75
+ A raw threshold is hard to set: a typical change's impact varies by orders of magnitude
76
+ across languages and projects. Instead of guessing a number, grade a change by its
77
+ **percentile** against a distribution, and gate on the percentile.
78
+
79
+ ```bash
80
+ # Build (or refresh) the project's own impact distribution from the merged history.
81
+ # Writes .impact-gate-baseline.json. Re-run it as the branch moves.
82
+ impact-gate baseline --base-ref main
83
+
84
+ # Gate on the grade instead of an absolute number.
85
+ impact-gate score --curve --warn-percentile 90 --block-percentile 98
86
+ ```
87
+
88
+ The grade blends two distributions:
89
+
90
+ - a **seed prior** shipped with the tool — per-language percentile tables built from a
91
+ 20-repo open-source corpus, with a pooled fallback for languages not in the table;
92
+ - the **project baseline** — the repo's own per-change distribution, walked from the
93
+ merged mainline (only landed work; in-flight branches are never reached).
94
+
95
+ The blend weights the project by `w = n / (n + K)`, where `n` is the number of landed
96
+ changes behind the baseline and `K` (`curve_prior_weight`, default 200) is how much
97
+ history it takes to trust the project over the seed. A fresh repo with no baseline file
98
+ grades on the seed alone; a deep history leans on itself. The grade shows in every
99
+ format next to the raw number.
100
+
101
+ ## Configure with `.impact-gate.yml` (repo root)
102
+
103
+ ```yaml
104
+ warn_at: 50000 # impact above which to warn
105
+ block_at: 200000 # impact above which to block
106
+ enforcement: warn # off, warn, or block. Start on warn. Flip to block when ready.
107
+ tolerance: 1.0 # CI-adjustable multiplier on both thresholds. Above 1 is more lenient.
108
+ # measure_config: .impact-measure.yml # optional: ignore globs and language overrides
109
+
110
+ # Grading curve (percentile gate). When enabled, warn_at/block_at are ignored and the
111
+ # gate uses the percentiles below instead.
112
+ curve_enabled: false # gate on the percentile grade instead of absolute numbers
113
+ warn_percentile: 90 # grade at or above this warns
114
+ block_percentile: 98 # grade at or above this blocks
115
+ curve_prior_weight: 200 # K in w = n/(n+K): history needed to trust the project over the seed
116
+ baseline_file: .impact-gate-baseline.json # where `impact-gate baseline` caches the distribution
117
+ ```
118
+
119
+ CLI flags override the file. A CI job can pass `--tolerance` or `--warn-at`. So a team
120
+ can dial tolerance without editing the repo. The curve knobs have flags too: `--curve`,
121
+ `--warn-percentile`, `--block-percentile`, `--baseline-file`.
122
+
123
+ ## Use in GitHub Actions
124
+
125
+ Add a workflow to your repo. The action scores the PR branch against its base and writes
126
+ a summary. `fetch-depth: 0` is required so the base branch and merge-base are present.
127
+
128
+ ```yaml
129
+ name: Change impact
130
+ on: pull_request
131
+ permissions:
132
+ contents: read
133
+ pull-requests: write # so the action can post the score as a PR comment
134
+ jobs:
135
+ impact:
136
+ runs-on: ubuntu-latest
137
+ steps:
138
+ - uses: actions/checkout@v5
139
+ with:
140
+ fetch-depth: 0
141
+ - uses: officefloor/ImpactGate@v1
142
+ with:
143
+ enforcement: warn # switch to block when ready
144
+ # warn-at: 50000
145
+ # block-at: 200000
146
+ # tolerance: 1.0
147
+ ```
148
+
149
+ The score appears in the job summary and as a sticky comment on the PR (one comment,
150
+ updated each run). In `block` mode the job fails when impact exceeds the block threshold.
151
+ Make the check required in branch protection to gate merges. The comment needs
152
+ `pull-requests: write`. Without it the run still passes and just skips the comment.
153
+
154
+ ## Roadmap
155
+
156
+ - Core CLI. Score staged, worktree, or range. Warn or block. Text, JSON, markdown. Done.
157
+ - GitHub Action. Composite action, job-summary report, and a sticky PR comment. Done.
158
+ - Baseline and grading curve. `impact-gate baseline` profiles the project history; the
159
+ gate blends a seed-corpus prior with the project's own distribution and grades a change
160
+ by its percentile (`score --curve`). Done.
161
+ - Distribution. `pip install impact-gate`, a `ghcr.io/officefloor/impact-gate` Docker
162
+ image for any CI, and a version-tagged Action (`@v0`). Done.
163
+ - More CI plugins. A GitLab CI template and a Jenkins shared library.
164
+ - Hooks and IDE. An `impact-gate install-hook` for pre-commit. Editor integration over LSP.
@@ -0,0 +1,8 @@
1
+ """impact-gate — report the change-impact of a change and gate on it.
2
+
3
+ A lightweight front-end over the change-impact measure (shared, single-sourced with
4
+ Surveyor / the PetClinic-Evolve harness). It scores a change against a base — a
5
+ committed range vs `main`, staged changes, or the working tree — reports the number,
6
+ and warns or blocks when the impact is too high.
7
+ """
8
+ __version__ = "0.1.0"