patchproof-core 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. patchproof/__init__.py +44 -0
  2. patchproof/__main__.py +8 -0
  3. patchproof/benchmarks/__init__.py +17 -0
  4. patchproof/benchmarks/swe_bench.py +159 -0
  5. patchproof/cli.py +1254 -0
  6. patchproof/core/__init__.py +33 -0
  7. patchproof/core/agent_init.py +103 -0
  8. patchproof/core/anti_cheat.py +396 -0
  9. patchproof/core/applier.py +159 -0
  10. patchproof/core/ast_analyzer.py +254 -0
  11. patchproof/core/detector.py +78 -0
  12. patchproof/core/git_provider.py +298 -0
  13. patchproof/core/healer.py +104 -0
  14. patchproof/core/mutator.py +223 -0
  15. patchproof/core/normalizer.py +338 -0
  16. patchproof/core/polyglot_guard.py +167 -0
  17. patchproof/core/runtime_guard.py +188 -0
  18. patchproof/core/search_replace.py +222 -0
  19. patchproof/core/slicer.py +172 -0
  20. patchproof/core/sparse_tree.py +95 -0
  21. patchproof/docker/runner.Dockerfile +42 -0
  22. patchproof/exceptions.py +37 -0
  23. patchproof/factory/__init__.py +22 -0
  24. patchproof/factory/blast_radius.py +120 -0
  25. patchproof/factory/engine.py +134 -0
  26. patchproof/factory/models.py +75 -0
  27. patchproof/mcp.py +532 -0
  28. patchproof/models/__init__.py +57 -0
  29. patchproof/models/ast.py +78 -0
  30. patchproof/models/patch.py +106 -0
  31. patchproof/models/sandbox.py +417 -0
  32. patchproof/reporting/__init__.py +19 -0
  33. patchproof/reporting/asymmetric.py +88 -0
  34. patchproof/reporting/badge.py +86 -0
  35. patchproof/reporting/certificate.py +230 -0
  36. patchproof/reporting/diagnostic.py +330 -0
  37. patchproof/reporting/html_report.py +367 -0
  38. patchproof/reporting/in_toto.py +188 -0
  39. patchproof/reporting/markdown.py +179 -0
  40. patchproof/reporting/sbom.py +152 -0
  41. patchproof/sandbox/__init__.py +37 -0
  42. patchproof/sandbox/classifier.py +289 -0
  43. patchproof/sandbox/comparative.py +478 -0
  44. patchproof/sandbox/docker_cli.py +384 -0
  45. patchproof/sandbox/doctor.py +605 -0
  46. patchproof/sandbox/flakiness.py +87 -0
  47. patchproof/sandbox/network_bridge.py +145 -0
  48. patchproof/sandbox/parser.py +172 -0
  49. patchproof/sandbox/runner.py +424 -0
  50. patchproof/sandbox/setup_runner.py +261 -0
  51. patchproof_core-0.3.1.dist-info/METADATA +212 -0
  52. patchproof_core-0.3.1.dist-info/RECORD +56 -0
  53. patchproof_core-0.3.1.dist-info/WHEEL +5 -0
  54. patchproof_core-0.3.1.dist-info/entry_points.txt +2 -0
  55. patchproof_core-0.3.1.dist-info/licenses/LICENSE +13 -0
  56. patchproof_core-0.3.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,212 @@
1
+ Metadata-Version: 2.4
2
+ Name: patchproof-core
3
+ Version: 0.3.1
4
+ Summary: Deterministic code-patch verification and reliability engine for AI-assisted engineering
5
+ Author: PatchProof Team
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/ArnavSingha/Patchproof
8
+ Project-URL: Repository, https://github.com/ArnavSingha/Patchproof
9
+ Project-URL: Documentation, https://github.com/ArnavSingha/Patchproof#readme
10
+ Project-URL: Bug Tracker, https://github.com/ArnavSingha/Patchproof/issues
11
+ Keywords: testing,verification,sandbox,docker,ai-agents,anti-cheat,diff,patch,mcp
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Software Development :: Quality Assurance
15
+ Classifier: Topic :: Software Development :: Testing
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Operating System :: OS Independent
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
25
+ Requires-Dist: cryptography>=41.0.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
28
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
29
+ Requires-Dist: mypy>=1.10.0; extra == "dev"
30
+ Requires-Dist: build>=1.0.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # PatchProof
34
+
35
+ [![CI](https://github.com/ArnavSingha/Patchproof/actions/workflows/ci.yml/badge.svg)](https://github.com/ArnavSingha/Patchproof/actions/workflows/ci.yml)
36
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
37
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
38
+ [![Code style: ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
39
+ [![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
40
+
41
+ **Deterministic Code-Patch Verification & Reliability Engine for AI-Assisted Engineering**
42
+
43
+ PatchProof is an independent verification subsystem designed to evaluate, test, and validate AI-generated code patches (from Aider, Claude Code, Cursor, Copilot, Windsurf, etc.) using isolated zero-network container sandboxes, AST dependency analysis, Spectrum-Based Fault Localization, flakiness disambiguation, and cryptographic proof-of-patch attestation.
44
+
45
+ ---
46
+
47
+ ## Key Features
48
+
49
+ - **Anti-Cheat Test Tampering Guard:** Prevents autonomous agents from evading failures by modifying the test suite. Audits AST deltas across test files to detect and reject assertion count reductions, test function deletions, and `@pytest.mark.skip` suppression injections.
50
+ - **Isolated Container Sandboxing:** Executes tests in hardened, zero-network Docker containers (`--network none`, `--read-only`, unprivileged UID `10001:10001`, dropped capabilities) with ephemeral staging workspaces and symlink traversal defense.
51
+ - **Predictive Test Slicing (`--slice`):** Analyzes patch AST import graphs to isolate and run only impacted tests in **< 5ms** instead of waiting for the full test suite.
52
+ - **Spectrum-Based Fault Localization (SBFL):** Correlates failing test tracebacks directly with patch hunks, calculating an **Ochiai suspicion score** and pinpointing the exact lines of code that triggered regressions.
53
+ - **Flakiness Disambiguation (`--disambiguate-flakes`):** Re-runs failing tests inside the sandbox across 3 retry attempts to disambiguate non-deterministic timing/race flakes from true deterministic regressions.
54
+ - **Autonomous Self-Healing Loop (`patchproof heal`):** Orchestrates multi-turn convergence loops using localized fault diagnostics to automatically repair regressions until the patch is clean.
55
+ - **Cryptographic Proof-of-Patch Attestation (`--cert`):** Generates tamper-proof HMAC-SHA256 signed verification certificates (`patchproof.cert.json`) for CI/CD and pull request merge gating.
56
+ - **One-Command Agent Onboarding (`patchproof init-agent`):** Automatically configures `.aider.conf.yml`, `.cursor/mcp.json`, `.cursorrules`, and `CLAUDE.md`.
57
+ - **Model Context Protocol (MCP) Server:** Built-in JSON-RPC stdio MCP server exposing verification, diagnostics, and certificates directly to AI coding agents.
58
+
59
+ ---
60
+
61
+ ## Quickstart
62
+
63
+ ### Installation
64
+
65
+ ```bash
66
+ pip install patchproof-core
67
+ ```
68
+
69
+ *(Installs the `patchproof` CLI and `import patchproof` Python package.)*
70
+
71
+ Or install in development mode from source:
72
+
73
+ ```bash
74
+ git clone https://github.com/ArnavSingha/Patchproof.git
75
+ cd patchproof
76
+ pip install -e ".[dev]"
77
+ ```
78
+
79
+ ---
80
+
81
+ ## CLI Usage
82
+
83
+ ### 1. Verify Patches in Isolated Sandbox
84
+
85
+ ```bash
86
+ # Verify a patch file with predictive slicing and flakiness disambiguation
87
+ patchproof verify changes.patch --slice --disambiguate-flakes
88
+
89
+ # Verify uncommitted Git changes in current repository
90
+ patchproof verify --git --slice
91
+
92
+ # Verify changes introduced by the latest HEAD commit
93
+ patchproof verify --head
94
+
95
+ # Print high-density AI diagnostic prompt if regressions occur
96
+ patchproof verify --git --ai-feedback
97
+
98
+ # Generate a visual HTML report, Proof-of-Patch certificate, and SVG badge
99
+ patchproof verify changes.patch --html report.html --cert cert.json --badge badge.svg
100
+ ```
101
+
102
+ ### 2. Autonomous Patch Self-Healing
103
+
104
+ ```bash
105
+ # Automatically verify and repair uncommitted Git regressions
106
+ patchproof heal --git --max-iterations 3
107
+
108
+ # Heal a patch file
109
+ patchproof heal changes.patch
110
+ ```
111
+
112
+ ### 3. Validate Cryptographic Proof Certificates
113
+
114
+ ```bash
115
+ # Validate that a Proof-of-Patch certificate is authentic and untampered
116
+ patchproof verify-cert cert.json
117
+ ```
118
+
119
+ ### 4. Setup AI Agent Presets
120
+
121
+ ```bash
122
+ # Initialize configuration for all agents (Aider, Cursor, Claude Code)
123
+ patchproof init-agent all
124
+
125
+ # Or initialize a specific agent
126
+ patchproof init-agent cursor
127
+ patchproof init-agent aider
128
+ patchproof init-agent claude
129
+ ```
130
+
131
+ ### 5. Diagnostics & Runner Setup
132
+
133
+ ```bash
134
+ # Check host Docker daemon, Linux container mode, and environment readiness
135
+ patchproof doctor
136
+
137
+ # Automatically remediate repairable environment issues (e.g. build missing runner)
138
+ patchproof doctor --fix
139
+
140
+ # Build standard local Docker runner image
141
+ patchproof setup-runner
142
+
143
+ # Build tailored runner pre-caching repository dependencies (sub-second zero-network tests)
144
+ patchproof setup-runner --from-repo .
145
+
146
+ # Install Git pre-commit verification hook
147
+ patchproof install-hooks
148
+ ```
149
+
150
+ ---
151
+
152
+ ## GitHub Action Integration
153
+
154
+ Add PatchProof verification, predictive test slicing, and Anti-Cheat PR gating to your repository in 3 lines:
155
+
156
+ ```yaml
157
+ name: PatchProof Verification
158
+ on: [pull_request, push]
159
+
160
+ jobs:
161
+ verify:
162
+ runs-on: ubuntu-latest
163
+ steps:
164
+ - uses: actions/checkout@v4
165
+ - uses: ArnavSingha/Patchproof@main
166
+ with:
167
+ slice: true
168
+ anti_cheat: true
169
+ comment_pr: true
170
+ ```
171
+
172
+ When triggered on a pull request, PatchProof automatically posts a rich, interactive **Proof Card** comment, updates `$GITHUB_STEP_SUMMARY`, and fails-closed if any test was weakened, deleted, or regressed.
173
+
174
+ ---
175
+
176
+ ## MCP Server Integration
177
+
178
+ PatchProof includes a built-in MCP server for AI coding assistants. Configure your MCP client:
179
+
180
+ ```json
181
+ {
182
+ "mcpServers": {
183
+ "patchproof": {
184
+ "command": "patchproof",
185
+ "args": ["mcp"]
186
+ }
187
+ }
188
+ }
189
+ ```
190
+
191
+ Or run `patchproof init-agent cursor` to automatically configure your `.cursor/mcp.json`.
192
+
193
+ ---
194
+
195
+ ## Development & Testing
196
+
197
+ ```bash
198
+ # Run unit and integration tests (385+ tests)
199
+ pytest
200
+
201
+ # Code formatting and linting
202
+ ruff check .
203
+
204
+ # Strict static type verification
205
+ mypy --strict src/ tests/
206
+ ```
207
+
208
+ ---
209
+
210
+ ## License
211
+
212
+ This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,56 @@
1
+ patchproof/__init__.py,sha256=Zu5Z8HysWZ_jbpAAcOh9jW4SLIvUfKKPRNtdEZv-ap8,1026
2
+ patchproof/__main__.py,sha256=EUrrxWiX5tYvnR5UEHeLh3ftt58Hcpn5myBvLCt7jpk,137
3
+ patchproof/cli.py,sha256=hpKqqtyo7etMzLzybLgK-oh4Yb1CzJlN9H6biP3xt3E,47843
4
+ patchproof/exceptions.py,sha256=6KfD8pd6c64-s3DArXSStpypBzvZDsm5-eBBzjZQEog,1248
5
+ patchproof/mcp.py,sha256=tpuQmShYnVKAd0FRVsaR8kolS6fJHp3YymNd9JeQhcQ,18492
6
+ patchproof/benchmarks/__init__.py,sha256=EfOebVCjDBAiUVb6kVVCHu8zxcEar6Iu6OopqtDb6kU,447
7
+ patchproof/benchmarks/swe_bench.py,sha256=mtlGNhMSfcQZwX2A0Fb4pHHjosvlO9xFRSt9BFkHYgU,5154
8
+ patchproof/core/__init__.py,sha256=dBdmktuiQ5hiEwJF-7RKmlSbIdSQZQj5GKDvFCiYeu0,910
9
+ patchproof/core/agent_init.py,sha256=EDGt-udSgQP87RfmAoRefauKTUC2fRkwWm0Kh76hNHo,3782
10
+ patchproof/core/anti_cheat.py,sha256=72rIyMCdeoFiBPk85_Ws0DANw-iq2OVaipXjLgLd0u0,14229
11
+ patchproof/core/applier.py,sha256=m6hJzQH4f1gYaPBjuZueyMcgr_z8JY556wgTAazF9Rw,6176
12
+ patchproof/core/ast_analyzer.py,sha256=TqKWqyddCMqeh8d-Q24V9zSC9Vooeul-Y6Y2U-A3YOY,8719
13
+ patchproof/core/detector.py,sha256=DpMoSuMmznO3YakDU67gWycqhKcWu8jQdLnvEMsNcq4,2235
14
+ patchproof/core/git_provider.py,sha256=HOQZG0KE7bgfJo0y8m0zgsnSkTKvmWsHDaM1-qFpmEU,10136
15
+ patchproof/core/healer.py,sha256=Dy6G7Kz3HsngcAIfGa2_Tz6Q8A26z2t201fpZVVmq8s,3520
16
+ patchproof/core/mutator.py,sha256=6AnErVKjX1jgoFCY9DaTElguQ7z325aDybV5pWLXOcg,7885
17
+ patchproof/core/normalizer.py,sha256=95mOJ50GXm5tG4SYOPcjZ-_HRUWuiLig4i4ewneNlFY,11525
18
+ patchproof/core/polyglot_guard.py,sha256=o8i7A5eoxG7961_2i54gektc9pWjVdP_zLbscJHn7rI,5564
19
+ patchproof/core/runtime_guard.py,sha256=nkzl3rC0mIG_Uy6f7-yubw1PZAM5QGoJH5_o-MvRgB0,7063
20
+ patchproof/core/search_replace.py,sha256=V5B2ibUwT_X-ZUTgk_CEQOmpoY_3JyNTJwtJFRNc6KI,7706
21
+ patchproof/core/slicer.py,sha256=lQcvXemGsCcl4OIIBjjyfvZcSKARQEGxqWW8rb5G7OQ,5601
22
+ patchproof/core/sparse_tree.py,sha256=oLQYjO8nOc8Mj3j5pW_RpVov0sjOxtwlY9BWOmgf3_I,3294
23
+ patchproof/docker/runner.Dockerfile,sha256=DMvJ8ZdS6FL8MdApeeY4jBYJhm3izEceXT-xYzX-bWg,1430
24
+ patchproof/factory/__init__.py,sha256=aCBGUq4fQscU-_ahPU4yU56feNQcXlyfedpER3BNqe4,516
25
+ patchproof/factory/blast_radius.py,sha256=m8gZb1orafZ_Ihgz11nK1ma7WOnHVlE9ChsxgzJFL4w,4505
26
+ patchproof/factory/engine.py,sha256=1tIWzI8alu-LrfWkvXeQYTUtHF6CfKqlro2Wf3WU9sM,4992
27
+ patchproof/factory/models.py,sha256=_XSiP1B-lf3ZhLKOV_kZWzhZLAeJSvf2dC2v3Ii4XvU,2698
28
+ patchproof/models/__init__.py,sha256=buEKVDh84cdPGOpUBhcXooCgNOLm9Ccnc9H9jRu3gWo,1150
29
+ patchproof/models/ast.py,sha256=p6eUmF9jiL-9wGvgpIlahOAtqwObV7UDbNVUlNZN-a0,2769
30
+ patchproof/models/patch.py,sha256=UQf1gJ6mXozVeYN3RQf4tBzmyEfjqzla0XV06OqYdh0,3809
31
+ patchproof/models/sandbox.py,sha256=_s_PB9L7P-tdJefE5zymZAk7oDKpZjaEXO4PnMkW-tQ,15418
32
+ patchproof/reporting/__init__.py,sha256=cuKRDQBAqXJ34FcAv6uvoC96HanjzwxS3_IVUAOfwrw,556
33
+ patchproof/reporting/asymmetric.py,sha256=4mjr7ja3JDj5KWPd3LpD2k9KCsUjVwzy9gv4fT80LEk,2777
34
+ patchproof/reporting/badge.py,sha256=EVs9-DQcqVvJGRZj5jfG6IL7bVYBTV7Vk1qeaS1kXsQ,2813
35
+ patchproof/reporting/certificate.py,sha256=blmWHfoRPLITU3ovDrqIRn71rb0rPFZbcAcnJagJ4Jg,8295
36
+ patchproof/reporting/diagnostic.py,sha256=d27oMNJltu_zWbdqzMrGIJRlFej3tBnoOjq61jjr93Y,12057
37
+ patchproof/reporting/html_report.py,sha256=6nQJDTXqhZLV8IUswZZ2soXWBHGeRO26G3XgEv0HvB0,10595
38
+ patchproof/reporting/in_toto.py,sha256=30za0VT73hRTfc09KbqvfYY8x6GtpBXE1Y_ZsQmWvu4,6427
39
+ patchproof/reporting/markdown.py,sha256=usXStcULt-GAiYu_Sbh7UIhxYMfep6UBIOQehk7_phM,7641
40
+ patchproof/reporting/sbom.py,sha256=-pjSmbU3CwTAuOkpJcrA9HEjkqld2qLIEtffY7BJVdw,5270
41
+ patchproof/sandbox/__init__.py,sha256=zZUmSw7Gs7cA_uErZcZaws8qzHLo__IysjZRcl1u5C8,1072
42
+ patchproof/sandbox/classifier.py,sha256=OxzySqF7hznQO1MkHNelE_XhQTPkSVoKzdKNaqNuFBQ,11871
43
+ patchproof/sandbox/comparative.py,sha256=4y1lU9tE3vsXgdaV9TwQiLU_hWDuTZGuB4k_CamSTN4,20543
44
+ patchproof/sandbox/docker_cli.py,sha256=HCzW68-4Bx3lC5acwoB4S2hOId9pyeoaQws9X3RSWqA,13733
45
+ patchproof/sandbox/doctor.py,sha256=FAbghV6sV_Xj-Y6AdMsjaA7867RqcrnnoG9x0duCeuA,23999
46
+ patchproof/sandbox/flakiness.py,sha256=Dwr7XZk8CUWvyuK4zt6uI3hg3BDCTAKnZ1a5xkiDZ8w,2573
47
+ patchproof/sandbox/network_bridge.py,sha256=Q208FW6_e4rrspZSpw-MaV3t8ejrqRiiePgzC7rztEM,4961
48
+ patchproof/sandbox/parser.py,sha256=NzHYzBfcaNR6dmT9JwVEYMnyXXnlr93RGIEwKZFGB5Y,6477
49
+ patchproof/sandbox/runner.py,sha256=XTMPI8Dlmy-tru2SKpvw7-M-kpNPL_K5lg2_wO2Ss20,15018
50
+ patchproof/sandbox/setup_runner.py,sha256=35lNJQsR69bK87lWA7v7pXPAlrINqba_aE_TejMU9FE,9286
51
+ patchproof_core-0.3.1.dist-info/licenses/LICENSE,sha256=Enf5W4gOLpsM3XnR0zjuObk34c3WFDcUzuNWYcSS098,564
52
+ patchproof_core-0.3.1.dist-info/METADATA,sha256=P8-9Z-JkI2XxDwvwXNuJMlAhALE7QIFduXCR4TUtLSE,7788
53
+ patchproof_core-0.3.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
54
+ patchproof_core-0.3.1.dist-info/entry_points.txt,sha256=S6jp7uSmPrC7ckZKeI3SeVPVBlxHXLr5TBQPBNA-on4,51
55
+ patchproof_core-0.3.1.dist-info/top_level.txt,sha256=MykdfBtmILEJMQHYmz2duJX6WUnxpQ9MlL3yrG8JvF0,11
56
+ patchproof_core-0.3.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ patchproof = patchproof.cli:main
@@ -0,0 +1,13 @@
1
+ Copyright 2026 PatchProof Contributors
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1 @@
1
+ patchproof