patchproof-core 0.3.1__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.
- patchproof_core-0.3.1/LICENSE +13 -0
- patchproof_core-0.3.1/MANIFEST.in +5 -0
- patchproof_core-0.3.1/PKG-INFO +212 -0
- patchproof_core-0.3.1/README.md +180 -0
- patchproof_core-0.3.1/action.yml +248 -0
- patchproof_core-0.3.1/docker/runner.Dockerfile +42 -0
- patchproof_core-0.3.1/pyproject.toml +102 -0
- patchproof_core-0.3.1/setup.cfg +4 -0
- patchproof_core-0.3.1/src/patchproof/__init__.py +44 -0
- patchproof_core-0.3.1/src/patchproof/__main__.py +8 -0
- patchproof_core-0.3.1/src/patchproof/benchmarks/__init__.py +17 -0
- patchproof_core-0.3.1/src/patchproof/benchmarks/swe_bench.py +159 -0
- patchproof_core-0.3.1/src/patchproof/cli.py +1254 -0
- patchproof_core-0.3.1/src/patchproof/core/__init__.py +33 -0
- patchproof_core-0.3.1/src/patchproof/core/agent_init.py +103 -0
- patchproof_core-0.3.1/src/patchproof/core/anti_cheat.py +396 -0
- patchproof_core-0.3.1/src/patchproof/core/applier.py +159 -0
- patchproof_core-0.3.1/src/patchproof/core/ast_analyzer.py +254 -0
- patchproof_core-0.3.1/src/patchproof/core/detector.py +78 -0
- patchproof_core-0.3.1/src/patchproof/core/git_provider.py +298 -0
- patchproof_core-0.3.1/src/patchproof/core/healer.py +104 -0
- patchproof_core-0.3.1/src/patchproof/core/mutator.py +223 -0
- patchproof_core-0.3.1/src/patchproof/core/normalizer.py +338 -0
- patchproof_core-0.3.1/src/patchproof/core/polyglot_guard.py +167 -0
- patchproof_core-0.3.1/src/patchproof/core/runtime_guard.py +188 -0
- patchproof_core-0.3.1/src/patchproof/core/search_replace.py +222 -0
- patchproof_core-0.3.1/src/patchproof/core/slicer.py +172 -0
- patchproof_core-0.3.1/src/patchproof/core/sparse_tree.py +95 -0
- patchproof_core-0.3.1/src/patchproof/docker/runner.Dockerfile +42 -0
- patchproof_core-0.3.1/src/patchproof/exceptions.py +37 -0
- patchproof_core-0.3.1/src/patchproof/factory/__init__.py +22 -0
- patchproof_core-0.3.1/src/patchproof/factory/blast_radius.py +120 -0
- patchproof_core-0.3.1/src/patchproof/factory/engine.py +134 -0
- patchproof_core-0.3.1/src/patchproof/factory/models.py +75 -0
- patchproof_core-0.3.1/src/patchproof/mcp.py +532 -0
- patchproof_core-0.3.1/src/patchproof/models/__init__.py +57 -0
- patchproof_core-0.3.1/src/patchproof/models/ast.py +78 -0
- patchproof_core-0.3.1/src/patchproof/models/patch.py +106 -0
- patchproof_core-0.3.1/src/patchproof/models/sandbox.py +417 -0
- patchproof_core-0.3.1/src/patchproof/reporting/__init__.py +19 -0
- patchproof_core-0.3.1/src/patchproof/reporting/asymmetric.py +88 -0
- patchproof_core-0.3.1/src/patchproof/reporting/badge.py +86 -0
- patchproof_core-0.3.1/src/patchproof/reporting/certificate.py +230 -0
- patchproof_core-0.3.1/src/patchproof/reporting/diagnostic.py +330 -0
- patchproof_core-0.3.1/src/patchproof/reporting/html_report.py +367 -0
- patchproof_core-0.3.1/src/patchproof/reporting/in_toto.py +188 -0
- patchproof_core-0.3.1/src/patchproof/reporting/markdown.py +179 -0
- patchproof_core-0.3.1/src/patchproof/reporting/sbom.py +152 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/__init__.py +37 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/classifier.py +289 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/comparative.py +478 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/docker_cli.py +384 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/doctor.py +605 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/flakiness.py +87 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/network_bridge.py +145 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/parser.py +172 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/runner.py +424 -0
- patchproof_core-0.3.1/src/patchproof/sandbox/setup_runner.py +261 -0
- patchproof_core-0.3.1/src/patchproof_core.egg-info/PKG-INFO +212 -0
- patchproof_core-0.3.1/src/patchproof_core.egg-info/SOURCES.txt +62 -0
- patchproof_core-0.3.1/src/patchproof_core.egg-info/dependency_links.txt +1 -0
- patchproof_core-0.3.1/src/patchproof_core.egg-info/entry_points.txt +2 -0
- patchproof_core-0.3.1/src/patchproof_core.egg-info/requires.txt +8 -0
- patchproof_core-0.3.1/src/patchproof_core.egg-info/top_level.txt +1 -0
|
@@ -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,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
|
+
[](https://github.com/ArnavSingha/Patchproof/actions/workflows/ci.yml)
|
|
36
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
37
|
+
[](https://www.python.org/downloads/)
|
|
38
|
+
[](https://github.com/astral-sh/ruff)
|
|
39
|
+
[](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,180 @@
|
|
|
1
|
+
# PatchProof
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ArnavSingha/Patchproof/actions/workflows/ci.yml)
|
|
4
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](https://github.com/astral-sh/ruff)
|
|
7
|
+
[](https://mypy-lang.org/)
|
|
8
|
+
|
|
9
|
+
**Deterministic Code-Patch Verification & Reliability Engine for AI-Assisted Engineering**
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Key Features
|
|
16
|
+
|
|
17
|
+
- **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.
|
|
18
|
+
- **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.
|
|
19
|
+
- **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.
|
|
20
|
+
- **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.
|
|
21
|
+
- **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.
|
|
22
|
+
- **Autonomous Self-Healing Loop (`patchproof heal`):** Orchestrates multi-turn convergence loops using localized fault diagnostics to automatically repair regressions until the patch is clean.
|
|
23
|
+
- **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.
|
|
24
|
+
- **One-Command Agent Onboarding (`patchproof init-agent`):** Automatically configures `.aider.conf.yml`, `.cursor/mcp.json`, `.cursorrules`, and `CLAUDE.md`.
|
|
25
|
+
- **Model Context Protocol (MCP) Server:** Built-in JSON-RPC stdio MCP server exposing verification, diagnostics, and certificates directly to AI coding agents.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quickstart
|
|
30
|
+
|
|
31
|
+
### Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install patchproof-core
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
*(Installs the `patchproof` CLI and `import patchproof` Python package.)*
|
|
38
|
+
|
|
39
|
+
Or install in development mode from source:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/ArnavSingha/Patchproof.git
|
|
43
|
+
cd patchproof
|
|
44
|
+
pip install -e ".[dev]"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## CLI Usage
|
|
50
|
+
|
|
51
|
+
### 1. Verify Patches in Isolated Sandbox
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Verify a patch file with predictive slicing and flakiness disambiguation
|
|
55
|
+
patchproof verify changes.patch --slice --disambiguate-flakes
|
|
56
|
+
|
|
57
|
+
# Verify uncommitted Git changes in current repository
|
|
58
|
+
patchproof verify --git --slice
|
|
59
|
+
|
|
60
|
+
# Verify changes introduced by the latest HEAD commit
|
|
61
|
+
patchproof verify --head
|
|
62
|
+
|
|
63
|
+
# Print high-density AI diagnostic prompt if regressions occur
|
|
64
|
+
patchproof verify --git --ai-feedback
|
|
65
|
+
|
|
66
|
+
# Generate a visual HTML report, Proof-of-Patch certificate, and SVG badge
|
|
67
|
+
patchproof verify changes.patch --html report.html --cert cert.json --badge badge.svg
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 2. Autonomous Patch Self-Healing
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Automatically verify and repair uncommitted Git regressions
|
|
74
|
+
patchproof heal --git --max-iterations 3
|
|
75
|
+
|
|
76
|
+
# Heal a patch file
|
|
77
|
+
patchproof heal changes.patch
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. Validate Cryptographic Proof Certificates
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Validate that a Proof-of-Patch certificate is authentic and untampered
|
|
84
|
+
patchproof verify-cert cert.json
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 4. Setup AI Agent Presets
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Initialize configuration for all agents (Aider, Cursor, Claude Code)
|
|
91
|
+
patchproof init-agent all
|
|
92
|
+
|
|
93
|
+
# Or initialize a specific agent
|
|
94
|
+
patchproof init-agent cursor
|
|
95
|
+
patchproof init-agent aider
|
|
96
|
+
patchproof init-agent claude
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 5. Diagnostics & Runner Setup
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Check host Docker daemon, Linux container mode, and environment readiness
|
|
103
|
+
patchproof doctor
|
|
104
|
+
|
|
105
|
+
# Automatically remediate repairable environment issues (e.g. build missing runner)
|
|
106
|
+
patchproof doctor --fix
|
|
107
|
+
|
|
108
|
+
# Build standard local Docker runner image
|
|
109
|
+
patchproof setup-runner
|
|
110
|
+
|
|
111
|
+
# Build tailored runner pre-caching repository dependencies (sub-second zero-network tests)
|
|
112
|
+
patchproof setup-runner --from-repo .
|
|
113
|
+
|
|
114
|
+
# Install Git pre-commit verification hook
|
|
115
|
+
patchproof install-hooks
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## GitHub Action Integration
|
|
121
|
+
|
|
122
|
+
Add PatchProof verification, predictive test slicing, and Anti-Cheat PR gating to your repository in 3 lines:
|
|
123
|
+
|
|
124
|
+
```yaml
|
|
125
|
+
name: PatchProof Verification
|
|
126
|
+
on: [pull_request, push]
|
|
127
|
+
|
|
128
|
+
jobs:
|
|
129
|
+
verify:
|
|
130
|
+
runs-on: ubuntu-latest
|
|
131
|
+
steps:
|
|
132
|
+
- uses: actions/checkout@v4
|
|
133
|
+
- uses: ArnavSingha/Patchproof@main
|
|
134
|
+
with:
|
|
135
|
+
slice: true
|
|
136
|
+
anti_cheat: true
|
|
137
|
+
comment_pr: true
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
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.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## MCP Server Integration
|
|
145
|
+
|
|
146
|
+
PatchProof includes a built-in MCP server for AI coding assistants. Configure your MCP client:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"mcpServers": {
|
|
151
|
+
"patchproof": {
|
|
152
|
+
"command": "patchproof",
|
|
153
|
+
"args": ["mcp"]
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Or run `patchproof init-agent cursor` to automatically configure your `.cursor/mcp.json`.
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Development & Testing
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Run unit and integration tests (385+ tests)
|
|
167
|
+
pytest
|
|
168
|
+
|
|
169
|
+
# Code formatting and linting
|
|
170
|
+
ruff check .
|
|
171
|
+
|
|
172
|
+
# Strict static type verification
|
|
173
|
+
mypy --strict src/ tests/
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
name: "PatchProof Code Verification & Attestation"
|
|
2
|
+
description: "Deterministic sandbox verification, predictive test slicing, anti-cheat test auditing, and cryptographic proof cards for AI-assisted engineering"
|
|
3
|
+
author: "PatchProof Team"
|
|
4
|
+
branding:
|
|
5
|
+
icon: "shield-check"
|
|
6
|
+
color: "green"
|
|
7
|
+
|
|
8
|
+
inputs:
|
|
9
|
+
target:
|
|
10
|
+
description: "Verification target: 'head' (latest commit) or 'git' (working tree diff)"
|
|
11
|
+
required: false
|
|
12
|
+
default: "head"
|
|
13
|
+
slice:
|
|
14
|
+
description: "Enable predictive AST test slicing (< 5ms)"
|
|
15
|
+
required: false
|
|
16
|
+
default: "true"
|
|
17
|
+
anti_cheat:
|
|
18
|
+
description: "Enforce Anti-Cheat test tampering guard (reject test deletions/assertion drops)"
|
|
19
|
+
required: false
|
|
20
|
+
default: "true"
|
|
21
|
+
disambiguate_flakes:
|
|
22
|
+
description: "Re-run introduced regressions 3x in sandbox to filter non-deterministic flakes"
|
|
23
|
+
required: false
|
|
24
|
+
default: "true"
|
|
25
|
+
test_command:
|
|
26
|
+
description: "Optional custom test execution command (e.g. 'pytest tests/ -q' or 'npm test')"
|
|
27
|
+
required: false
|
|
28
|
+
image:
|
|
29
|
+
description: "Docker runner container image (default: auto-detected)"
|
|
30
|
+
required: false
|
|
31
|
+
html_report:
|
|
32
|
+
description: "Path to output standalone visual HTML evidence report"
|
|
33
|
+
required: false
|
|
34
|
+
default: "patchproof-report.html"
|
|
35
|
+
cert:
|
|
36
|
+
description: "Path to output cryptographic Proof-of-Patch certificate"
|
|
37
|
+
required: false
|
|
38
|
+
default: "patchproof.cert.json"
|
|
39
|
+
in_toto:
|
|
40
|
+
description: "Optional path to output signed in-toto v1.0 DSSE attestation envelope"
|
|
41
|
+
required: false
|
|
42
|
+
private_key:
|
|
43
|
+
description: "Optional Ed25519 private key file or PEM string to cryptographically sign the certificate"
|
|
44
|
+
required: false
|
|
45
|
+
signer_identity:
|
|
46
|
+
description: "Signer identity URI or handle (e.g. github.com/owner/repo/ci)"
|
|
47
|
+
required: false
|
|
48
|
+
comment_pr:
|
|
49
|
+
description: "Automatically post/update rich Markdown proof card as a PR comment"
|
|
50
|
+
required: false
|
|
51
|
+
default: "true"
|
|
52
|
+
github_token:
|
|
53
|
+
description: "GitHub token for posting PR comments and step summaries"
|
|
54
|
+
required: false
|
|
55
|
+
default: ${{ github.token }}
|
|
56
|
+
|
|
57
|
+
outputs:
|
|
58
|
+
verdict:
|
|
59
|
+
description: "Evaluation verdict: accepted, rejected, suspicious, or inconclusive"
|
|
60
|
+
value: ${{ steps.run-patchproof.outputs.verdict }}
|
|
61
|
+
cert_path:
|
|
62
|
+
description: "Path to generated cryptographic ProofCertificate"
|
|
63
|
+
value: ${{ steps.run-patchproof.outputs.cert_path }}
|
|
64
|
+
in_toto_path:
|
|
65
|
+
description: "Path to generated in-toto DSSE attestation envelope"
|
|
66
|
+
value: ${{ steps.run-patchproof.outputs.in_toto_path }}
|
|
67
|
+
summary_path:
|
|
68
|
+
description: "Path to generated Markdown summary card"
|
|
69
|
+
value: ${{ steps.run-patchproof.outputs.summary_path }}
|
|
70
|
+
|
|
71
|
+
runs:
|
|
72
|
+
using: "composite"
|
|
73
|
+
steps:
|
|
74
|
+
- name: Set up Python
|
|
75
|
+
uses: actions/setup-python@v5
|
|
76
|
+
with:
|
|
77
|
+
python-version: "3.11"
|
|
78
|
+
|
|
79
|
+
- name: Install PatchProof
|
|
80
|
+
shell: bash
|
|
81
|
+
run: |
|
|
82
|
+
PKG_DIR="${{ github.action_path }}"
|
|
83
|
+
while [ "$PKG_DIR" != "/" ] && [ "$PKG_DIR" != "." ] && [ ! -f "$PKG_DIR/pyproject.toml" ]; do
|
|
84
|
+
PKG_DIR="$(dirname "$PKG_DIR")"
|
|
85
|
+
done
|
|
86
|
+
python -m pip install --upgrade pip
|
|
87
|
+
if [ -f "$PKG_DIR/pyproject.toml" ]; then
|
|
88
|
+
pip install "$PKG_DIR"
|
|
89
|
+
else
|
|
90
|
+
pip install patchproof-core
|
|
91
|
+
fi
|
|
92
|
+
|
|
93
|
+
- name: Run PatchProof Doctor
|
|
94
|
+
shell: bash
|
|
95
|
+
env:
|
|
96
|
+
INPUT_IMAGE: ${{ inputs.image }}
|
|
97
|
+
run: |
|
|
98
|
+
DOCTOR_ARGS=("doctor" "--fix")
|
|
99
|
+
if [ -n "$INPUT_IMAGE" ]; then
|
|
100
|
+
DOCTOR_ARGS+=("--image" "$INPUT_IMAGE")
|
|
101
|
+
fi
|
|
102
|
+
patchproof "${DOCTOR_ARGS[@]}"
|
|
103
|
+
|
|
104
|
+
- name: Execute PatchProof Verification
|
|
105
|
+
id: run-patchproof
|
|
106
|
+
shell: bash
|
|
107
|
+
env:
|
|
108
|
+
INPUT_TARGET: ${{ inputs.target }}
|
|
109
|
+
INPUT_SLICE: ${{ inputs.slice }}
|
|
110
|
+
INPUT_ANTI_CHEAT: ${{ inputs.anti_cheat }}
|
|
111
|
+
INPUT_DISAMBIGUATE_FLAKES: ${{ inputs.disambiguate_flakes }}
|
|
112
|
+
INPUT_TEST_COMMAND: ${{ inputs.test_command }}
|
|
113
|
+
INPUT_IMAGE: ${{ inputs.image }}
|
|
114
|
+
INPUT_HTML_REPORT: ${{ inputs.html_report }}
|
|
115
|
+
INPUT_CERT: ${{ inputs.cert }}
|
|
116
|
+
INPUT_IN_TOTO: ${{ inputs.in_toto }}
|
|
117
|
+
INPUT_PRIVATE_KEY: ${{ inputs.private_key }}
|
|
118
|
+
INPUT_SIGNER_IDENTITY: ${{ inputs.signer_identity }}
|
|
119
|
+
run: |
|
|
120
|
+
ARGS=("verify")
|
|
121
|
+
if [ "$INPUT_TARGET" = "head" ]; then
|
|
122
|
+
ARGS+=("--head")
|
|
123
|
+
else
|
|
124
|
+
ARGS+=("--git")
|
|
125
|
+
fi
|
|
126
|
+
|
|
127
|
+
if [ "$INPUT_SLICE" = "true" ]; then
|
|
128
|
+
ARGS+=("--slice")
|
|
129
|
+
fi
|
|
130
|
+
|
|
131
|
+
if [ "$INPUT_ANTI_CHEAT" = "false" ]; then
|
|
132
|
+
ARGS+=("--allow-test-edits")
|
|
133
|
+
fi
|
|
134
|
+
|
|
135
|
+
if [ "$INPUT_DISAMBIGUATE_FLAKES" = "true" ]; then
|
|
136
|
+
ARGS+=("--disambiguate-flakes")
|
|
137
|
+
fi
|
|
138
|
+
|
|
139
|
+
if [ -n "$INPUT_TEST_COMMAND" ]; then
|
|
140
|
+
ARGS+=("-c" "$INPUT_TEST_COMMAND")
|
|
141
|
+
fi
|
|
142
|
+
|
|
143
|
+
if [ -n "$INPUT_IMAGE" ]; then
|
|
144
|
+
ARGS+=("--image" "$INPUT_IMAGE")
|
|
145
|
+
fi
|
|
146
|
+
|
|
147
|
+
if [ -n "$INPUT_HTML_REPORT" ]; then
|
|
148
|
+
ARGS+=("--html" "$INPUT_HTML_REPORT")
|
|
149
|
+
fi
|
|
150
|
+
|
|
151
|
+
if [ -n "$INPUT_CERT" ]; then
|
|
152
|
+
ARGS+=("--cert" "$INPUT_CERT")
|
|
153
|
+
fi
|
|
154
|
+
|
|
155
|
+
if [ -n "$INPUT_IN_TOTO" ]; then
|
|
156
|
+
ARGS+=("--in-toto" "$INPUT_IN_TOTO")
|
|
157
|
+
fi
|
|
158
|
+
|
|
159
|
+
if [ -n "$INPUT_PRIVATE_KEY" ]; then
|
|
160
|
+
ARGS+=("--private-key" "$INPUT_PRIVATE_KEY")
|
|
161
|
+
fi
|
|
162
|
+
|
|
163
|
+
if [ -n "$INPUT_SIGNER_IDENTITY" ]; then
|
|
164
|
+
ARGS+=("--signer-identity" "$INPUT_SIGNER_IDENTITY")
|
|
165
|
+
fi
|
|
166
|
+
|
|
167
|
+
SUMMARY_FILE="patchproof-summary.md"
|
|
168
|
+
ARGS+=("--markdown" "$SUMMARY_FILE")
|
|
169
|
+
|
|
170
|
+
set +e
|
|
171
|
+
patchproof "${ARGS[@]}"
|
|
172
|
+
EXIT_CODE=$?
|
|
173
|
+
|
|
174
|
+
case $EXIT_CODE in
|
|
175
|
+
0) VERDICT="accepted" ;;
|
|
176
|
+
1) VERDICT="rejected" ;;
|
|
177
|
+
2) VERDICT="suspicious" ;;
|
|
178
|
+
3) VERDICT="inconclusive" ;;
|
|
179
|
+
4) VERDICT="infrastructure_failure" ;;
|
|
180
|
+
*) VERDICT="error" ;;
|
|
181
|
+
esac
|
|
182
|
+
|
|
183
|
+
echo "verdict=$VERDICT" >> "$GITHUB_OUTPUT"
|
|
184
|
+
echo "cert_path=$INPUT_CERT" >> "$GITHUB_OUTPUT"
|
|
185
|
+
echo "in_toto_path=$INPUT_IN_TOTO" >> "$GITHUB_OUTPUT"
|
|
186
|
+
echo "summary_path=$SUMMARY_FILE" >> "$GITHUB_OUTPUT"
|
|
187
|
+
|
|
188
|
+
if [ -n "$GITHUB_STEP_SUMMARY" ] && [ -f "$SUMMARY_FILE" ]; then
|
|
189
|
+
cat "$SUMMARY_FILE" >> "$GITHUB_STEP_SUMMARY"
|
|
190
|
+
fi
|
|
191
|
+
|
|
192
|
+
exit $EXIT_CODE
|
|
193
|
+
|
|
194
|
+
- name: Post PR Comment
|
|
195
|
+
if: always() && inputs.comment_pr == 'true' && github.event_name == 'pull_request' && inputs.github_token != ''
|
|
196
|
+
shell: bash
|
|
197
|
+
env:
|
|
198
|
+
GITHUB_TOKEN: ${{ inputs.github_token }}
|
|
199
|
+
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
200
|
+
REPO: ${{ github.repository }}
|
|
201
|
+
SUMMARY_FILE: ${{ steps.run-patchproof.outputs.summary_path }}
|
|
202
|
+
run: |
|
|
203
|
+
if [ -f "$SUMMARY_FILE" ]; then
|
|
204
|
+
python -c "
|
|
205
|
+
import json, os, urllib.request
|
|
206
|
+
|
|
207
|
+
token = os.environ.get('GITHUB_TOKEN')
|
|
208
|
+
repo = os.environ.get('REPO')
|
|
209
|
+
pr_number = os.environ.get('PR_NUMBER')
|
|
210
|
+
summary_file = os.environ.get('SUMMARY_FILE')
|
|
211
|
+
|
|
212
|
+
if not (token and repo and pr_number and summary_file and os.path.isfile(summary_file)):
|
|
213
|
+
exit(0)
|
|
214
|
+
|
|
215
|
+
with open(summary_file, 'r', encoding='utf-8') as f:
|
|
216
|
+
body = f.read()
|
|
217
|
+
|
|
218
|
+
headers = {
|
|
219
|
+
'Authorization': f'Bearer {token}',
|
|
220
|
+
'Accept': 'application/vnd.github+json',
|
|
221
|
+
'User-Agent': 'PatchProof-Action',
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
marker = '<!-- patchproof-attestation-marker -->'
|
|
225
|
+
url = f'https://api.github.com/repos/{repo}/issues/{pr_number}/comments'
|
|
226
|
+
try:
|
|
227
|
+
req = urllib.request.Request(url, headers=headers)
|
|
228
|
+
with urllib.request.urlopen(req) as resp:
|
|
229
|
+
comments = json.loads(resp.read().decode())
|
|
230
|
+
existing_id = None
|
|
231
|
+
for c in comments:
|
|
232
|
+
if marker in c.get('body', ''):
|
|
233
|
+
existing_id = c['id']
|
|
234
|
+
break
|
|
235
|
+
|
|
236
|
+
payload = json.dumps({'body': body}).encode('utf-8')
|
|
237
|
+
if existing_id:
|
|
238
|
+
update_url = f'https://api.github.com/repos/{repo}/issues/comments/{existing_id}'
|
|
239
|
+
req = urllib.request.Request(update_url, data=payload, headers=headers, method='PATCH')
|
|
240
|
+
else:
|
|
241
|
+
req = urllib.request.Request(url, data=payload, headers=headers, method='POST')
|
|
242
|
+
|
|
243
|
+
with urllib.request.urlopen(req) as resp:
|
|
244
|
+
pass
|
|
245
|
+
except Exception as e:
|
|
246
|
+
print(f'Warning: failed to post PR comment: {e}')
|
|
247
|
+
"
|
|
248
|
+
fi
|