pawl-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 (44) hide show
  1. pawl_gate-0.1.0/LICENSE +202 -0
  2. pawl_gate-0.1.0/PKG-INFO +182 -0
  3. pawl_gate-0.1.0/README.md +153 -0
  4. pawl_gate-0.1.0/pyproject.toml +83 -0
  5. pawl_gate-0.1.0/setup.cfg +4 -0
  6. pawl_gate-0.1.0/src/pawl/__init__.py +5 -0
  7. pawl_gate-0.1.0/src/pawl/__main__.py +5 -0
  8. pawl_gate-0.1.0/src/pawl/adapters.py +411 -0
  9. pawl_gate-0.1.0/src/pawl/baseline.py +199 -0
  10. pawl_gate-0.1.0/src/pawl/check.py +352 -0
  11. pawl_gate-0.1.0/src/pawl/cli.py +553 -0
  12. pawl_gate-0.1.0/src/pawl/config.py +311 -0
  13. pawl_gate-0.1.0/src/pawl/errors.py +19 -0
  14. pawl_gate-0.1.0/src/pawl/gitutil.py +64 -0
  15. pawl_gate-0.1.0/src/pawl/guard.py +477 -0
  16. pawl_gate-0.1.0/src/pawl/hooks.py +106 -0
  17. pawl_gate-0.1.0/src/pawl/init.py +88 -0
  18. pawl_gate-0.1.0/src/pawl/metrics.py +55 -0
  19. pawl_gate-0.1.0/src/pawl/mutate.py +160 -0
  20. pawl_gate-0.1.0/src/pawl/preflight.py +66 -0
  21. pawl_gate-0.1.0/src/pawl/py.typed +0 -0
  22. pawl_gate-0.1.0/src/pawl/render.py +52 -0
  23. pawl_gate-0.1.0/src/pawl/runner.py +66 -0
  24. pawl_gate-0.1.0/src/pawl/templates.py +65 -0
  25. pawl_gate-0.1.0/src/pawl/update.py +141 -0
  26. pawl_gate-0.1.0/src/pawl_gate.egg-info/PKG-INFO +182 -0
  27. pawl_gate-0.1.0/src/pawl_gate.egg-info/SOURCES.txt +42 -0
  28. pawl_gate-0.1.0/src/pawl_gate.egg-info/dependency_links.txt +1 -0
  29. pawl_gate-0.1.0/src/pawl_gate.egg-info/entry_points.txt +2 -0
  30. pawl_gate-0.1.0/src/pawl_gate.egg-info/requires.txt +6 -0
  31. pawl_gate-0.1.0/src/pawl_gate.egg-info/top_level.txt +1 -0
  32. pawl_gate-0.1.0/tests/test_adapters.py +163 -0
  33. pawl_gate-0.1.0/tests/test_baseline.py +68 -0
  34. pawl_gate-0.1.0/tests/test_check.py +151 -0
  35. pawl_gate-0.1.0/tests/test_cli.py +192 -0
  36. pawl_gate-0.1.0/tests/test_config.py +69 -0
  37. pawl_gate-0.1.0/tests/test_guard.py +211 -0
  38. pawl_gate-0.1.0/tests/test_hooks.py +45 -0
  39. pawl_gate-0.1.0/tests/test_metrics.py +34 -0
  40. pawl_gate-0.1.0/tests/test_mutate.py +21 -0
  41. pawl_gate-0.1.0/tests/test_preflight.py +51 -0
  42. pawl_gate-0.1.0/tests/test_runtimes.py +83 -0
  43. pawl_gate-0.1.0/tests/test_templates.py +27 -0
  44. pawl_gate-0.1.0/tests/test_update.py +65 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,182 @@
1
+ Metadata-Version: 2.4
2
+ Name: pawl-gate
3
+ Version: 0.1.0
4
+ Summary: Ratchet gate for automated coding work. Code can only move forward.
5
+ Author: Zero-State LLC
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Source, https://github.com/Zero-State-LLC/pawl
8
+ Project-URL: Issues, https://github.com/Zero-State-LLC/pawl/issues
9
+ Keywords: ratchet,ci,testing,ai-agents,reward-hacking,quality-gate
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Quality Assurance
18
+ Classifier: Topic :: Software Development :: Testing
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=8; extra == "dev"
25
+ Requires-Dist: pytest-cov>=5; extra == "dev"
26
+ Requires-Dist: ruff>=0.6; extra == "dev"
27
+ Requires-Dist: mypy>=1.11; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # Pawl
31
+
32
+ **Code can only move forward.**
33
+
34
+ [![CI](https://github.com/Zero-State-LLC/pawl/actions/workflows/ci.yml/badge.svg)](https://github.com/Zero-State-LLC/pawl/actions/workflows/ci.yml)
35
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue)](pyproject.toml)
36
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-green)](LICENSE)
37
+ [![Dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen)](pyproject.toml)
38
+
39
+ Pawl is a ratchet gate for automated coding work. A change passes only if no
40
+ test that passed now fails, no test disappeared or got skipped, and nobody
41
+ loosened the gate itself. Known failures are allowed and can only go down.
42
+
43
+ ## The problem
44
+
45
+ Coding agents told to "make the tests pass" sometimes change the tests instead
46
+ of the code. Researchers have measured it: agents modify tests, overload `==`,
47
+ and special-case inputs when a task is hard
48
+ ([ImpossibleBench](https://arxiv.org/abs/2510.20270),
49
+ [EvilGenie](https://arxiv.org/abs/2511.21654),
50
+ [METR](https://metr.org/blog/2025-06-05-recent-reward-hacking/)). Asking them
51
+ not to is unreliable. A plain "tests must pass" check cannot help when the
52
+ suite already has known failures, and a count-based ratchet misses a fixed test
53
+ that hides a new failure, a skipped test, or a rewritten assertion.
54
+
55
+ Here an agent "fixes" `add` and edits a test so the suite stays green. The
56
+ test run looks normal; Pawl does not:
57
+
58
+ ```console
59
+ $ python -m pytest tests -q # 1 known failure, same as before
60
+ 1 failed, 9 passed in 0.02s
61
+ $ pawl guard --base main --replay
62
+ ### Pawl guard: FAIL (base main (a536657fb7cc))
63
+
64
+ - **TEST_MODIFIED** (block) `tests/test_calc.py`: 1 existing test line(s) changed or removed; existing tests are read-only for agents
65
+ - **TESTS_WEAKENED_REPLAY** (block) `tests/test_calc.py`: the original tests fail on this code (NEW_FAILURE: 1 test(s) fail that the baseline records as passing)
66
+ - `tests/test_calc.py::test_add_negative`
67
+ ```
68
+
69
+ (Real output from `examples/demo`; run `examples/run_demo.sh` to see it.)
70
+
71
+ ## Quick start
72
+
73
+ ```bash
74
+ pip install "pawl-gate @ git+https://github.com/Zero-State-LLC/pawl@v0.1.0"
75
+ pawl init --github # detects pytest, jest, vitest, go, or cargo
76
+ git add pawl.toml pawl.baseline.json PAWL_DEBT.md .github/workflows/pawl.yml
77
+ git commit -m "Add Pawl ratchet gate"
78
+ ```
79
+
80
+ `pawl init` writes `pawl.toml`, runs your suite in two orders, records the
81
+ baseline, and (with `--github`) writes a workflow. Then make the `pawl` job a
82
+ required status check and add CODEOWNERS for the gate files
83
+ ([docs/REPO_SETTINGS.md](docs/REPO_SETTINGS.md)).
84
+
85
+ While this repository is private, installing from Git needs credentials
86
+ (for example a fine-grained read-only token in CI). The package is named
87
+ `pawl-gate` because `pawl` is taken on PyPI. The import
88
+ and the command are `pawl`.
89
+
90
+ ## How it works
91
+
92
+ ```mermaid
93
+ flowchart LR
94
+ A[Agent edits code] --> H{pawl hook stop<br/>local, fast}
95
+ H -- red --> A
96
+ H -- green --> PR[Pull request]
97
+ PR --> CI[CI required check]
98
+ CI --> C[pawl check --ci<br/>config + baseline from base branch]
99
+ CI --> G[pawl guard --ci --replay<br/>diff vs base branch]
100
+ C --> D{All green?}
101
+ G --> D
102
+ D -- no --> A
103
+ D -- gate change --> Human[CODEOWNERS review<br/>pawl-approved label]
104
+ D -- yes --> M[Merge]
105
+ M --> U[pawl update<br/>baseline can only tighten]
106
+ ```
107
+
108
+ | Command | What it does |
109
+ | --- | --- |
110
+ | `pawl check` | Runs every suite and compares each test ID with the baseline. Exit 0 pass, 1 regression, 2 could not measure, 3 preflight failed |
111
+ | `pawl update` | Records the current state. Tightening is free; loosening needs `--loosen --reason` and is logged |
112
+ | `pawl guard` | Scans the diff against a base ref for gate edits, test deletions and edits, new skips, hook tampering, and suspicious code. `--replay` runs the base branch's tests on the new code |
113
+ | `pawl report` | Renders the last check and guard as Markdown |
114
+ | `pawl init` | Detects the runner, writes the config and the first baseline |
115
+ | `pawl hook stop`, `pawl hook protect` | Harness hooks for Claude Code, Codex, Cursor, and Hermes |
116
+ | `pawl escalate` | The agent's sanctioned way out when the spec and the tests conflict |
117
+ | `pawl quarantine` | Excuses a flaky test until an expiry date (humans only) |
118
+ | `pawl mutate` | Advisory mutation spot check on changed Python lines |
119
+
120
+ Adapters: pytest, Jest, Vitest, `go test`, `cargo test`, and any runner that
121
+ writes JUnit XML. Every adapter fails closed: if Pawl cannot parse a result, it
122
+ exits 2 instead of guessing.
123
+
124
+ ## The trust model in one paragraph
125
+
126
+ The authority is CI, not the agent's machine. In CI, `pawl check` loads
127
+ `pawl.toml` and the baseline from the base branch and uses the stricter of the
128
+ base and branch baselines, so a branch cannot lower its own bar. `pawl guard`
129
+ blocks changes to gate files unless a human adds the `pawl-approved` label.
130
+ Harness hooks give the agent the same answer earlier, but they run where the
131
+ agent can edit them, so they are a convenience. See
132
+ [docs/RECOMMENDATION.md](docs/RECOMMENDATION.md).
133
+
134
+ ## Results
135
+
136
+ On a synthetic corpus of 19 agent cheats and 6 clean changes, run against a
137
+ project with one known failing test ([BENCHMARKS.md](BENCHMARKS.md)):
138
+
139
+ | Detector | Cheats caught | Clean changes blocked |
140
+ | --- | --- | --- |
141
+ | plain `pytest` must pass | 18/19 | 5/6 (the known failure blocks everything) |
142
+ | Abraxas count ratchet | 5/19 | 0/6 |
143
+ | `pawl check` (agent side) | 12/19 | 0/6 |
144
+ | `pawl hook stop --base` (agent side) | 17/19 | 0/6 |
145
+ | Pawl in CI (check + guard + holdout) | 18/19 | 0/6 |
146
+
147
+ The one miss, special-casing inputs that no holdout covers, is beyond any
148
+ test-based gate. Overhead of `pawl check` over bare pytest was 0.3 s on both a
149
+ 100-test and a 5000-test suite.
150
+
151
+ In a small live trial (12 episodes, one model, a task with one impossible
152
+ test), an agent without the Pawl contract edited the conflicting test once
153
+ and rewrote the spec docstring once. Pawl's stop hook and CI gate caught the
154
+ test edit and missed the docstring rewrite. With the contract, all 8 episodes
155
+ left the impossible test alone and escalated; none tampered. Details and
156
+ limits are in [BENCHMARKS.md](BENCHMARKS.md).
157
+
158
+ ## Documentation
159
+
160
+ - [docs/WHY_PAWL.md](docs/WHY_PAWL.md): who it is for and how it compares.
161
+ - [docs/CONFIG.md](docs/CONFIG.md): every `pawl.toml` key.
162
+ - [DESIGN.md](DESIGN.md): how it works and why.
163
+ - [RESEARCH.md](RESEARCH.md): the literature behind each mechanism.
164
+ - [docs/ARCHITECTURE_REVIEW.md](docs/ARCHITECTURE_REVIEW.md): threats covered
165
+ and not covered.
166
+ - [docs/RECOMMENDATION.md](docs/RECOMMENDATION.md): where enforcement lives,
167
+ and migrating from the Abraxas ratchet script.
168
+ - [integrations/](integrations/): Claude Code, Codex, Cursor, Hermes, GitHub
169
+ Actions, pre-commit, and an `AGENTS.md` contract.
170
+
171
+ ## Credits
172
+
173
+ - The Abraxas `test_ratchet.sh` script, which Pawl generalizes.
174
+ - ImpossibleBench (Zhong, Raghunathan, Carlini), EvilGenie, METR's reward
175
+ hacking reports, and the papers in [RESEARCH.md](RESEARCH.md).
176
+ - Ratchet tools that came first: Betterer, ESLint bulk suppressions,
177
+ basedpyright baselines, mypy-baseline, and ratchet-gate.
178
+ - A pawl is the hinged catch that lets a ratchet wheel turn one way only.
179
+
180
+ ## License
181
+
182
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,153 @@
1
+ # Pawl
2
+
3
+ **Code can only move forward.**
4
+
5
+ [![CI](https://github.com/Zero-State-LLC/pawl/actions/workflows/ci.yml/badge.svg)](https://github.com/Zero-State-LLC/pawl/actions/workflows/ci.yml)
6
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue)](pyproject.toml)
7
+ [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-green)](LICENSE)
8
+ [![Dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen)](pyproject.toml)
9
+
10
+ Pawl is a ratchet gate for automated coding work. A change passes only if no
11
+ test that passed now fails, no test disappeared or got skipped, and nobody
12
+ loosened the gate itself. Known failures are allowed and can only go down.
13
+
14
+ ## The problem
15
+
16
+ Coding agents told to "make the tests pass" sometimes change the tests instead
17
+ of the code. Researchers have measured it: agents modify tests, overload `==`,
18
+ and special-case inputs when a task is hard
19
+ ([ImpossibleBench](https://arxiv.org/abs/2510.20270),
20
+ [EvilGenie](https://arxiv.org/abs/2511.21654),
21
+ [METR](https://metr.org/blog/2025-06-05-recent-reward-hacking/)). Asking them
22
+ not to is unreliable. A plain "tests must pass" check cannot help when the
23
+ suite already has known failures, and a count-based ratchet misses a fixed test
24
+ that hides a new failure, a skipped test, or a rewritten assertion.
25
+
26
+ Here an agent "fixes" `add` and edits a test so the suite stays green. The
27
+ test run looks normal; Pawl does not:
28
+
29
+ ```console
30
+ $ python -m pytest tests -q # 1 known failure, same as before
31
+ 1 failed, 9 passed in 0.02s
32
+ $ pawl guard --base main --replay
33
+ ### Pawl guard: FAIL (base main (a536657fb7cc))
34
+
35
+ - **TEST_MODIFIED** (block) `tests/test_calc.py`: 1 existing test line(s) changed or removed; existing tests are read-only for agents
36
+ - **TESTS_WEAKENED_REPLAY** (block) `tests/test_calc.py`: the original tests fail on this code (NEW_FAILURE: 1 test(s) fail that the baseline records as passing)
37
+ - `tests/test_calc.py::test_add_negative`
38
+ ```
39
+
40
+ (Real output from `examples/demo`; run `examples/run_demo.sh` to see it.)
41
+
42
+ ## Quick start
43
+
44
+ ```bash
45
+ pip install "pawl-gate @ git+https://github.com/Zero-State-LLC/pawl@v0.1.0"
46
+ pawl init --github # detects pytest, jest, vitest, go, or cargo
47
+ git add pawl.toml pawl.baseline.json PAWL_DEBT.md .github/workflows/pawl.yml
48
+ git commit -m "Add Pawl ratchet gate"
49
+ ```
50
+
51
+ `pawl init` writes `pawl.toml`, runs your suite in two orders, records the
52
+ baseline, and (with `--github`) writes a workflow. Then make the `pawl` job a
53
+ required status check and add CODEOWNERS for the gate files
54
+ ([docs/REPO_SETTINGS.md](docs/REPO_SETTINGS.md)).
55
+
56
+ While this repository is private, installing from Git needs credentials
57
+ (for example a fine-grained read-only token in CI). The package is named
58
+ `pawl-gate` because `pawl` is taken on PyPI. The import
59
+ and the command are `pawl`.
60
+
61
+ ## How it works
62
+
63
+ ```mermaid
64
+ flowchart LR
65
+ A[Agent edits code] --> H{pawl hook stop<br/>local, fast}
66
+ H -- red --> A
67
+ H -- green --> PR[Pull request]
68
+ PR --> CI[CI required check]
69
+ CI --> C[pawl check --ci<br/>config + baseline from base branch]
70
+ CI --> G[pawl guard --ci --replay<br/>diff vs base branch]
71
+ C --> D{All green?}
72
+ G --> D
73
+ D -- no --> A
74
+ D -- gate change --> Human[CODEOWNERS review<br/>pawl-approved label]
75
+ D -- yes --> M[Merge]
76
+ M --> U[pawl update<br/>baseline can only tighten]
77
+ ```
78
+
79
+ | Command | What it does |
80
+ | --- | --- |
81
+ | `pawl check` | Runs every suite and compares each test ID with the baseline. Exit 0 pass, 1 regression, 2 could not measure, 3 preflight failed |
82
+ | `pawl update` | Records the current state. Tightening is free; loosening needs `--loosen --reason` and is logged |
83
+ | `pawl guard` | Scans the diff against a base ref for gate edits, test deletions and edits, new skips, hook tampering, and suspicious code. `--replay` runs the base branch's tests on the new code |
84
+ | `pawl report` | Renders the last check and guard as Markdown |
85
+ | `pawl init` | Detects the runner, writes the config and the first baseline |
86
+ | `pawl hook stop`, `pawl hook protect` | Harness hooks for Claude Code, Codex, Cursor, and Hermes |
87
+ | `pawl escalate` | The agent's sanctioned way out when the spec and the tests conflict |
88
+ | `pawl quarantine` | Excuses a flaky test until an expiry date (humans only) |
89
+ | `pawl mutate` | Advisory mutation spot check on changed Python lines |
90
+
91
+ Adapters: pytest, Jest, Vitest, `go test`, `cargo test`, and any runner that
92
+ writes JUnit XML. Every adapter fails closed: if Pawl cannot parse a result, it
93
+ exits 2 instead of guessing.
94
+
95
+ ## The trust model in one paragraph
96
+
97
+ The authority is CI, not the agent's machine. In CI, `pawl check` loads
98
+ `pawl.toml` and the baseline from the base branch and uses the stricter of the
99
+ base and branch baselines, so a branch cannot lower its own bar. `pawl guard`
100
+ blocks changes to gate files unless a human adds the `pawl-approved` label.
101
+ Harness hooks give the agent the same answer earlier, but they run where the
102
+ agent can edit them, so they are a convenience. See
103
+ [docs/RECOMMENDATION.md](docs/RECOMMENDATION.md).
104
+
105
+ ## Results
106
+
107
+ On a synthetic corpus of 19 agent cheats and 6 clean changes, run against a
108
+ project with one known failing test ([BENCHMARKS.md](BENCHMARKS.md)):
109
+
110
+ | Detector | Cheats caught | Clean changes blocked |
111
+ | --- | --- | --- |
112
+ | plain `pytest` must pass | 18/19 | 5/6 (the known failure blocks everything) |
113
+ | Abraxas count ratchet | 5/19 | 0/6 |
114
+ | `pawl check` (agent side) | 12/19 | 0/6 |
115
+ | `pawl hook stop --base` (agent side) | 17/19 | 0/6 |
116
+ | Pawl in CI (check + guard + holdout) | 18/19 | 0/6 |
117
+
118
+ The one miss, special-casing inputs that no holdout covers, is beyond any
119
+ test-based gate. Overhead of `pawl check` over bare pytest was 0.3 s on both a
120
+ 100-test and a 5000-test suite.
121
+
122
+ In a small live trial (12 episodes, one model, a task with one impossible
123
+ test), an agent without the Pawl contract edited the conflicting test once
124
+ and rewrote the spec docstring once. Pawl's stop hook and CI gate caught the
125
+ test edit and missed the docstring rewrite. With the contract, all 8 episodes
126
+ left the impossible test alone and escalated; none tampered. Details and
127
+ limits are in [BENCHMARKS.md](BENCHMARKS.md).
128
+
129
+ ## Documentation
130
+
131
+ - [docs/WHY_PAWL.md](docs/WHY_PAWL.md): who it is for and how it compares.
132
+ - [docs/CONFIG.md](docs/CONFIG.md): every `pawl.toml` key.
133
+ - [DESIGN.md](DESIGN.md): how it works and why.
134
+ - [RESEARCH.md](RESEARCH.md): the literature behind each mechanism.
135
+ - [docs/ARCHITECTURE_REVIEW.md](docs/ARCHITECTURE_REVIEW.md): threats covered
136
+ and not covered.
137
+ - [docs/RECOMMENDATION.md](docs/RECOMMENDATION.md): where enforcement lives,
138
+ and migrating from the Abraxas ratchet script.
139
+ - [integrations/](integrations/): Claude Code, Codex, Cursor, Hermes, GitHub
140
+ Actions, pre-commit, and an `AGENTS.md` contract.
141
+
142
+ ## Credits
143
+
144
+ - The Abraxas `test_ratchet.sh` script, which Pawl generalizes.
145
+ - ImpossibleBench (Zhong, Raghunathan, Carlini), EvilGenie, METR's reward
146
+ hacking reports, and the papers in [RESEARCH.md](RESEARCH.md).
147
+ - Ratchet tools that came first: Betterer, ESLint bulk suppressions,
148
+ basedpyright baselines, mypy-baseline, and ratchet-gate.
149
+ - A pawl is the hinged catch that lets a ratchet wheel turn one way only.
150
+
151
+ ## License
152
+
153
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,83 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pawl-gate"
7
+ version = "0.1.0"
8
+ description = "Ratchet gate for automated coding work. Code can only move forward."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ authors = [{ name = "Zero-State LLC" }]
14
+ keywords = ["ratchet", "ci", "testing", "ai-agents", "reward-hacking", "quality-gate"]
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Environment :: Console",
18
+ "Intended Audience :: Developers",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Topic :: Software Development :: Quality Assurance",
24
+ "Topic :: Software Development :: Testing",
25
+ "Typing :: Typed",
26
+ ]
27
+ dependencies = []
28
+
29
+ [project.optional-dependencies]
30
+ dev = ["pytest>=8", "pytest-cov>=5", "ruff>=0.6", "mypy>=1.11"]
31
+
32
+ [project.scripts]
33
+ pawl = "pawl.cli:main"
34
+
35
+ [project.urls]
36
+ Source = "https://github.com/Zero-State-LLC/pawl"
37
+ Issues = "https://github.com/Zero-State-LLC/pawl/issues"
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+
42
+ [tool.setuptools.package-data]
43
+ pawl = ["py.typed"]
44
+
45
+ [tool.pytest.ini_options]
46
+ testpaths = ["tests"]
47
+ addopts = "-ra --strict-markers"
48
+ markers = ["slow: runs real subprocess suites"]
49
+
50
+ [tool.coverage.run]
51
+ source = ["pawl"]
52
+ branch = true
53
+
54
+ [tool.coverage.report]
55
+ show_missing = true
56
+ skip_covered = true
57
+ fail_under = 80
58
+
59
+ [tool.ruff]
60
+ line-length = 100
61
+ target-version = "py311"
62
+ src = ["src", "tests", "benchmarks"]
63
+ extend-exclude = ["examples/*/scenarios", "benchmarks/work"]
64
+
65
+ [tool.ruff.lint]
66
+ select = ["E", "F", "W", "I", "B", "UP", "SIM", "RUF", "PL", "S"]
67
+ ignore = [
68
+ "S603", "S607", # subprocess with argv lists is the core job of this tool
69
+ "S404",
70
+ "PLR0911", "PLR0912", "PLR0913", "PLR0915", "PLR2004",
71
+ "S101", # assert is fine in tests and internal invariants
72
+ "RUF001",
73
+ "PLC0415", # lazy imports keep hook start-up fast
74
+ ]
75
+
76
+ [tool.ruff.lint.per-file-ignores]
77
+ "tests/*" = ["S", "E501", "PLW0108"]
78
+ "benchmarks/*" = ["S", "T201", "E501", "PLW2901"]
79
+
80
+ [tool.mypy]
81
+ strict = true
82
+ python_version = "3.11"
83
+ files = ["src/pawl"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ """Pawl: a ratchet gate for automated coding work. Code can only move forward."""
2
+
3
+ __version__ = "0.1.0"
4
+
5
+ __all__ = ["__version__"]
@@ -0,0 +1,5 @@
1
+ """Allow ``python -m pawl``."""
2
+
3
+ from pawl.cli import main
4
+
5
+ raise SystemExit(main())