openfix-cli 0.4.0__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.
openfix/verify.py ADDED
@@ -0,0 +1,251 @@
1
+ """Independent verification. Nothing here trusts the model's account of what it did."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import re
7
+ import shutil
8
+ from dataclasses import asdict, dataclass, field
9
+ from pathlib import Path
10
+ from typing import Any
11
+
12
+ from .agent.prompts import REVIEW_SYSTEM, review_prompt
13
+ from .agent.tools import render_finding
14
+ from .findings import Finding
15
+ from .gitutil import file_at, worktree
16
+ from .providers import Provider, ProviderError
17
+ from .redact import redact_text
18
+ from .sandbox import CommandResult, Sandbox
19
+ from .scanners import Scanner, ScanResult, line_map, matches
20
+
21
+ PASSED, FAILED, NOT_RUN, INCONCLUSIVE = "passed", "failed", "not_run", "inconclusive"
22
+
23
+
24
+ @dataclass
25
+ class Check:
26
+ name: str
27
+ status: str
28
+ detail: str
29
+ evidence: dict[str, Any] = field(default_factory=dict)
30
+
31
+ def to_dict(self) -> dict[str, Any]:
32
+ return asdict(self)
33
+
34
+
35
+ def _cmd_evidence(res: CommandResult | None) -> dict[str, Any]:
36
+ if res is None:
37
+ return {}
38
+ return {
39
+ "command": res.command,
40
+ "exit_code": res.exit_code,
41
+ "duration_s": res.duration_s,
42
+ "timed_out": res.timed_out,
43
+ "output_tail": res.tail(1500),
44
+ }
45
+
46
+
47
+ def detect_test_command(repo: Path) -> str | None:
48
+ pkg = repo / "package.json"
49
+ if pkg.is_file():
50
+ try:
51
+ scripts = json.loads(pkg.read_text(encoding="utf-8")).get("scripts") or {}
52
+ except json.JSONDecodeError:
53
+ scripts = {}
54
+ test = scripts.get("test", "")
55
+ if test and "no test specified" not in test:
56
+ return "npm test --silent"
57
+ has_py = (repo / "pyproject.toml").is_file() or (repo / "pytest.ini").is_file() or (repo / "tests").is_dir()
58
+ if has_py and (any(repo.rglob("test_*.py")) or any(repo.rglob("*_test.py"))):
59
+ return "python -m pytest -q -x"
60
+ if (repo / "go.mod").is_file():
61
+ return "go test ./..."
62
+ if (repo / "Cargo.toml").is_file():
63
+ return "cargo test --quiet"
64
+ if (repo / "pom.xml").is_file():
65
+ return "mvn -q -B test"
66
+ if (repo / "build.gradle").is_file() or (repo / "build.gradle.kts").is_file():
67
+ return "./gradlew test --quiet"
68
+ return None
69
+
70
+
71
+ def detect_setup_command(repo: Path) -> str | None:
72
+ if (repo / "package.json").is_file() and not (repo / "node_modules").exists():
73
+ if (repo / "package-lock.json").exists():
74
+ return "npm ci --ignore-scripts --no-audit --no-fund"
75
+ if (repo / "pnpm-lock.yaml").exists():
76
+ return "corepack pnpm install --frozen-lockfile --ignore-scripts"
77
+ if (repo / "yarn.lock").exists():
78
+ return "corepack yarn install --frozen-lockfile --ignore-scripts"
79
+ deps = json.loads((repo / "package.json").read_text(encoding="utf-8"))
80
+ if deps.get("dependencies") or deps.get("devDependencies"):
81
+ return "npm install --ignore-scripts --no-audit --no-fund"
82
+ return None
83
+
84
+
85
+ # ----------------------------------------------------------------------------- rescan
86
+
87
+
88
+ def scan_target(
89
+ scanner: Scanner, work: Path, finding: Finding, base_sources: dict[str, str] | None = None
90
+ ) -> tuple[ScanResult, list[Finding]]:
91
+ result = scanner.scan(work)
92
+ lm = None
93
+ loc = finding.location
94
+ if base_sources is not None and loc and loc.path in base_sources and (work / loc.path).exists():
95
+ lm = line_map(base_sources[loc.path], (work / loc.path).read_text(encoding="utf-8", errors="replace"))
96
+ return result, [c for c in result.findings if matches(finding, c, lm)]
97
+
98
+
99
+ def check_rescan(
100
+ base: tuple[ScanResult, list[Finding]] | None, head: tuple[ScanResult, list[Finding]] | None, scanner: Scanner
101
+ ) -> Check:
102
+ if base is None or head is None:
103
+ return Check("rescan", NOT_RUN, f"Scanner unavailable ({scanner.description})")
104
+ (b_res, b_hits), (h_res, h_hits) = base, head
105
+ ev = {
106
+ "scanner": scanner.description,
107
+ "base_matches": [f.short() for f in b_hits],
108
+ "head_matches": [f.short() for f in h_hits],
109
+ "base_total": len(b_res.findings),
110
+ "head_total": len(h_res.findings),
111
+ "base_run": _cmd_evidence(b_res.command),
112
+ "head_run": _cmd_evidence(h_res.command),
113
+ }
114
+ if b_res.error or h_res.error:
115
+ return Check("rescan", NOT_RUN, f"Scanner error: {b_res.error or h_res.error}", ev)
116
+ if not b_hits:
117
+ return Check(
118
+ "rescan",
119
+ INCONCLUSIVE,
120
+ "The scanner did not reproduce the finding on the original code, so its absence after the "
121
+ "patch proves nothing.",
122
+ ev,
123
+ )
124
+ if h_hits:
125
+ return Check("rescan", FAILED, "The scanner still reports the finding on the patched code.", ev)
126
+ return Check("rescan", PASSED, "Reproduced on the original code; not reported on the patched code.", ev)
127
+
128
+
129
+ # ----------------------------------------------------------------------------- tests
130
+
131
+
132
+ def check_tests(base_run: CommandResult | None, head_run: CommandResult | None, command: str | None) -> Check:
133
+ if not command or head_run is None:
134
+ return Check("tests", NOT_RUN, "No test command configured or detected.")
135
+ ev = {"head_run": _cmd_evidence(head_run), "base_run": _cmd_evidence(base_run)}
136
+ if head_run.ok:
137
+ return Check("tests", PASSED, f"`{command}` passes on the patched code.", ev)
138
+ if base_run is not None and not base_run.ok:
139
+ return Check(
140
+ "tests",
141
+ INCONCLUSIVE,
142
+ f"`{command}` fails on the patched code, but it already failed on the original code.",
143
+ ev,
144
+ )
145
+ return Check("tests", FAILED, f"`{command}` fails on the patched code but passed on the original.", ev)
146
+
147
+
148
+ def check_regression_test(
149
+ repo: Path,
150
+ base_commit: str,
151
+ work: Path,
152
+ test_path: str | None,
153
+ command: str | None,
154
+ sandbox: Sandbox,
155
+ setup: str | None,
156
+ head_tests: CommandResult | None,
157
+ base_tests: CommandResult | None,
158
+ subdir: str = ".",
159
+ ) -> Check:
160
+ """Differential proof: the new test must fail on the original code and pass on the patched code."""
161
+ if not test_path:
162
+ return Check("regression_test", NOT_RUN, "The agent did not add a regression test.")
163
+ if not command:
164
+ return Check("regression_test", NOT_RUN, "No test command to run the regression test with.")
165
+ if base_tests is not None and not base_tests.ok:
166
+ return Check(
167
+ "regression_test",
168
+ INCONCLUSIVE,
169
+ "The test suite already fails on the original code, so a failing run proves nothing.",
170
+ )
171
+ repo_path = test_path if subdir == "." else f"{subdir}/{test_path}"
172
+ if file_at(repo, base_commit, repo_path) is not None:
173
+ return Check(
174
+ "regression_test", INCONCLUSIVE, f"{test_path} already existed; a differential check needs a new test file."
175
+ )
176
+ test_src = (work / test_path).resolve()
177
+ if work.resolve() not in test_src.parents or not test_src.is_file() or test_src.is_symlink():
178
+ return Check("regression_test", FAILED, f"{test_path} is not a regular file inside the checkout.")
179
+ with worktree(repo, base_commit) as base_root:
180
+ base = base_root if subdir == "." else base_root / subdir
181
+ dest = (base / test_path).resolve()
182
+ if base.resolve() not in dest.parents:
183
+ return Check("regression_test", FAILED, f"{test_path} resolves outside the checkout.")
184
+ dest.parent.mkdir(parents=True, exist_ok=True)
185
+ shutil.copy2(test_src, dest)
186
+ if sandbox.kind == "local":
187
+ _link_deps(work, base)
188
+ if setup and not (base / "node_modules").exists():
189
+ sandbox.run(setup, base, timeout=1200, network=True)
190
+ before = sandbox.run(command, base, timeout=900)
191
+ ev = {"test": test_path, "original_with_test": _cmd_evidence(before), "patched": _cmd_evidence(head_tests)}
192
+ passes_after = head_tests is not None and head_tests.ok
193
+ if before.ok:
194
+ return Check(
195
+ "regression_test",
196
+ FAILED,
197
+ f"{test_path} passes on the original code, so it does not demonstrate the vulnerability.",
198
+ ev,
199
+ )
200
+ if not passes_after:
201
+ return Check(
202
+ "regression_test", FAILED, "The test suite (including the new test) fails on the patched code.", ev
203
+ )
204
+ return Check("regression_test", PASSED, f"{test_path} fails on the original code and passes with the fix.", ev)
205
+
206
+
207
+ def _link_deps(src: Path, dst: Path) -> None:
208
+ """Reuse installed dependencies between checkouts instead of reinstalling."""
209
+ for d in ("node_modules", ".venv", "vendor"):
210
+ if (src / d).is_dir() and not (dst / d).exists():
211
+ (dst / d).symlink_to((src / d).resolve(), target_is_directory=True)
212
+
213
+
214
+ # ----------------------------------------------------------------------------- review
215
+
216
+
217
+ def check_review(reviewer: Provider | None, finding: Finding, diff: str, summary: str, author: str) -> Check:
218
+ if reviewer is None:
219
+ return Check("review", NOT_RUN, "No reviewer model configured (models.reviewer).")
220
+ ref = f"{reviewer.name}:{reviewer.model}"
221
+ ev: dict[str, Any] = {"reviewer": ref, "author": author}
222
+ try:
223
+ convo = reviewer.start(REVIEW_SYSTEM, [])
224
+ turn = convo.send(user=review_prompt(render_finding(finding), redact_text(diff[:120_000]), summary))
225
+ except ProviderError as exc:
226
+ return Check("review", NOT_RUN, f"Reviewer unavailable: {exc}", ev)
227
+ ev["usage"] = {"input_tokens": turn.usage.input_tokens, "output_tokens": turn.usage.output_tokens}
228
+ m = re.search(r"\{.*\}", turn.text, re.S)
229
+ try:
230
+ verdict = json.loads(m.group(0)) if m else {}
231
+ except json.JSONDecodeError:
232
+ verdict = {}
233
+ if not isinstance(verdict, dict) or verdict.get("verdict") not in ("approve", "request_changes"):
234
+ ev["raw"] = turn.text[:2000]
235
+ return Check("review", INCONCLUSIVE, "Reviewer reply was not a valid verdict.", ev)
236
+ ev["verdict"] = verdict
237
+ same_vendor = ref.split(":")[0] == author.split(":")[0]
238
+ note = " (same provider as the author)" if same_vendor else ""
239
+ if verdict["verdict"] == "approve" and verdict.get("fixes_root_cause", True):
240
+ return Check("review", PASSED, f"{ref} approved{note}: {verdict.get('summary', '')}".strip(), ev)
241
+ concerns = "; ".join((verdict.get("bypasses") or []) + (verdict.get("concerns") or []))[:600]
242
+ return Check("review", FAILED, f"{ref} requested changes{note}: {concerns or verdict.get('summary', '')}", ev)
243
+
244
+
245
+ def overall(checks: list[Check], required: list[str]) -> str:
246
+ by = {c.name: c for c in checks}
247
+ if any(c.status == FAILED for c in checks):
248
+ return "failed"
249
+ if all(by.get(r) is not None and by[r].status == PASSED for r in required):
250
+ return "verified"
251
+ return "unverified"
@@ -0,0 +1,322 @@
1
+ Metadata-Version: 2.5
2
+ Name: openfix-cli
3
+ Version: 0.4.0
4
+ Summary: Model-agnostic security remediation agent. Every fix ships with proof.
5
+ Project-URL: Homepage, https://github.com/markusweldon/openfix
6
+ Project-URL: Documentation, https://github.com/markusweldon/openfix#documentation
7
+ Project-URL: Issues, https://github.com/markusweldon/openfix/issues
8
+ Project-URL: Changelog, https://github.com/markusweldon/openfix/releases
9
+ Author: Markus Weldon
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: agent,appsec,autofix,devsecops,llm,remediation,sarif,security
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Information Technology
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Security
25
+ Classifier: Topic :: Software Development :: Quality Assurance
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: httpx>=0.27
28
+ Requires-Dist: pydantic>=2.7
29
+ Requires-Dist: pyyaml>=6.0
30
+ Provides-Extra: all
31
+ Requires-Dist: anthropic>=0.69; extra == 'all'
32
+ Requires-Dist: google-genai>=1.0; extra == 'all'
33
+ Requires-Dist: openai>=1.50; extra == 'all'
34
+ Provides-Extra: anthropic
35
+ Requires-Dist: anthropic>=0.69; extra == 'anthropic'
36
+ Provides-Extra: dev
37
+ Requires-Dist: mypy>=1.11; extra == 'dev'
38
+ Requires-Dist: pytest>=8; extra == 'dev'
39
+ Requires-Dist: ruff>=0.6; extra == 'dev'
40
+ Requires-Dist: types-pyyaml; extra == 'dev'
41
+ Provides-Extra: gemini
42
+ Requires-Dist: google-genai>=1.0; extra == 'gemini'
43
+ Provides-Extra: openai
44
+ Requires-Dist: openai>=1.50; extra == 'openai'
45
+ Description-Content-Type: text/markdown
46
+
47
+ <div align="center">
48
+
49
+ <img alt="OpenFix" src="https://raw.githubusercontent.com/markusweldon/openfix/main/docs/assets/logo-dark.svg" width="480">
50
+
51
+ **Turn scanner findings into verified fixes, with any model, under your policy.**
52
+
53
+ [![CI](https://github.com/markusweldon/openfix/actions/workflows/ci.yml/badge.svg)](https://github.com/markusweldon/openfix/actions/workflows/ci.yml) [![Python](https://img.shields.io/badge/python-3.10%2B-3776ab)](https://github.com/markusweldon/openfix/blob/main/pyproject.toml) [![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/markusweldon/openfix/blob/main/LICENSE) [![Status: alpha](https://img.shields.io/badge/status-alpha-orange)](https://github.com/markusweldon/openfix/blob/main/ROADMAP.md)
54
+
55
+ [Quick start](#quick-start) · [How it works](#how-it-works) · [Policy](#policy-as-code) · [Models](#bring-any-model) · [GitHub Action](#github-action) · [Docs](#documentation)
56
+
57
+ </div>
58
+
59
+ ---
60
+
61
+ OpenFix reads the reports your scanners already produce: Semgrep, CodeQL, Snyk, Trivy, OSV-Scanner, Gitleaks, Dependabot, or anything that writes SARIF. A policy file decides which findings may be fixed. The model you choose writes a minimal patch in a throwaway checkout, and OpenFix then **checks the patch without trusting the model**. A fix only counts when the scanner, your tests and a new regression test all agree.
62
+
63
+ Every fix comes with a **receipt**: a signed, re-checkable record of what changed, why it was allowed, which model wrote it and what proved it works.
64
+
65
+ <br>
66
+
67
+ <img alt="OpenFix pipeline. Ingest: any scanner report is normalized. Policy: openfix.yaml decides autofix, propose or skip. Agent: any model edits a disposable worktree using policy-checked tools only. Verify: rescan, tests, regression test and optional review, independent of the agent. Ship: receipt.json, patch.diff, SARIF fixes and a draft PR." src="https://raw.githubusercontent.com/markusweldon/openfix/main/docs/assets/architecture-dark.svg" width="100%">
68
+
69
+ **Models propose. Code verifies.** The model writes the patch. Your scanner, your tests and a new regression test prove it, or it doesn't ship.
70
+
71
+ <br>
72
+
73
+ <img alt="OpenFix implementation. Scanners in: Snyk, Semgrep, GitHub CodeQL and Dependabot, Trivy, or any SARIF, plus openfix.yaml. OpenFix core: ingest.py, policy.py and engine.py hand each finding to a disposable git worktree (gitutil.py), where agent/loop.py talks to Claude, Gemini, OpenAI, Grok or Ollama through providers/ using tool calls only. verify.py then runs rescan, tests, regression test and review, using sandbox.py (Docker, no network) and scanners.py. Results out: receipt.json, patch.diff, openfix.sarif, summary.md and a GitHub draft pull request. Runs as a CLI or GitHub Action on Python 3.10+." src="https://raw.githubusercontent.com/markusweldon/openfix/main/docs/assets/implementation-dark.svg" width="100%">
74
+
75
+ <br>
76
+
77
+ <img alt="Terminal demo. Snyk Code found a command injection in /ping and Semgrep found a path traversal in readUserFile. One openfix fix command takes both reports. For each finding it shows rescan, tests and regression test passed, then verified, with a link to the draft pull request it opened. The demo then shows that pull request on GitHub, with the finding, the change and a table of passed checks. It ends on: 2 scanners in, 2 verified fixes out." src="https://raw.githubusercontent.com/markusweldon/openfix/main/docs/assets/demo-dark.gif" width="100%">
78
+
79
+ Demo example from <code>examples/vulnerable-app</code> with <a href="https://github.com/markusweldon/openfix/blob/main/docs/demo/record.py"><code>docs/demo/record.py</code></a>. The model's tool calls are replayed so anyone can rerun it without an API key; Snyk Code, Semgrep, the tests and GitHub are real. The pull request in the demo is live: <a href="https://github.com/markusweldon/openfix-demo/pull/2">markusweldon/openfix-demo#2</a>. Waiting is sped up.
80
+
81
+ <br>
82
+
83
+ ## Why OpenFix
84
+
85
+ <table>
86
+ <tr>
87
+ <td width="50%" valign="top">
88
+
89
+ ### 🔌 Any model
90
+ Claude, OpenAI, Gemini, Grok, OpenRouter, Groq, DeepSeek, Mistral, Together, Fireworks, any OpenAI-compatible gateway, or a local model through Ollama, vLLM or LM Studio. Change it with one flag: `--model provider:model`.
91
+
92
+ </td>
93
+ <td width="50%" valign="top">
94
+
95
+ ### ✅ Proof, not prose
96
+ Verification is a separate step. It never asks the model whether the fix worked. Findings that a fresh scan can't reproduce are dropped **before** any model is called, so stale results cost nothing.
97
+
98
+ </td>
99
+ </tr>
100
+ <tr>
101
+ <td valign="top">
102
+
103
+ ### 📜 Policy as code
104
+ One YAML file decides what is auto-fixed, what only gets a proposed patch, and what is never sent to a model. It also sets change-size limits, protected paths, budgets, and which code may only be seen by local models.
105
+
106
+ </td>
107
+ <td valign="top">
108
+
109
+ ### 🧱 A small blast radius
110
+ The agent has no shell, no network and no git. It can read, search and edit files, run your tests and re-run the scanner, and every write is checked against the policy. Tests run in a Docker container with networking off.
111
+
112
+ </td>
113
+ </tr>
114
+ <tr>
115
+ <td valign="top">
116
+
117
+ ### ⚙️ Deterministic when it can be
118
+ A vulnerable direct dependency is bumped to the lowest fixed version with no model involved. That is cheaper, faster and reproducible.
119
+
120
+ </td>
121
+ <td valign="top">
122
+
123
+ ### 🧾 Fits your pipeline
124
+ CLI and GitHub Action. SARIF in and SARIF out (with `fixes[]`). in-toto receipts with optional Sigstore signing. Draft PRs for humans to review. It never merges anything.
125
+
126
+ </td>
127
+ </tr>
128
+ </table>
129
+
130
+ ## Quick start
131
+
132
+ ```bash
133
+ pip install "openfix-cli[all]" # or: uv tool install "openfix-cli[all]"
134
+ export ANTHROPIC_API_KEY=... # or OPENAI_API_KEY, GEMINI_API_KEY, XAI_API_KEY, ... (openfix providers)
135
+
136
+ semgrep scan --sarif -o semgrep.sarif # any scanner that writes SARIF or a supported JSON format
137
+ openfix plan semgrep.sarif # what the policy will do with each finding; no model calls
138
+ openfix fix semgrep.sarif # fix, verify, and write receipts to .openfix/runs/<timestamp>/
139
+ ```
140
+
141
+ Use a different model to write fixes than the one that reviews them, and open draft PRs for the fixes that pass:
142
+
143
+ ```bash
144
+ openfix fix semgrep.sarif --model openai:gpt-5 --reviewer anthropic:claude-opus-5-5 --open-prs
145
+ ```
146
+
147
+ <details>
148
+ <summary><b>Try it without an API key</b></summary>
149
+
150
+ <br>
151
+
152
+ The repository includes a deliberately vulnerable Node app, real Semgrep rules, and a recorded model session:
153
+
154
+ ```bash
155
+ git clone https://github.com/markusweldon/openfix && cd openfix
156
+ pip install -e . semgrep
157
+ cd examples/vulnerable-app
158
+ openfix fix findings/semgrep.sarif --only path-traversal-path-join-var \
159
+ --model scripted:demo/path-traversal.script.yaml --sandbox local
160
+ ```
161
+
162
+ ```text
163
+ → [high] path-traversal-path-join-var src/files.js:11 [autofix via rule 'code findings']
164
+ verified: all required checks passed (rescan, tests, regression_test)
165
+ ```
166
+
167
+ CI runs this same flow on every push.
168
+
169
+ </details>
170
+
171
+ ## How it works
172
+
173
+ | # | Stage | What happens |
174
+ |:-:|---|---|
175
+ | 1 | **Ingest** | Reports are detected and normalized into one finding model. Secret values are redacted and finding ids are sanitized, because reports are untrusted input. |
176
+ | 2 | **Policy** | The first matching rule in `openfix.yaml` decides `autofix`, `propose` or `skip`, and guards and budgets are applied. |
177
+ | 3 | **Reproduce** | A fresh scan of the original code must still report the finding. If it doesn't, the finding is dropped. |
178
+ | 4 | **Fix** | The model works in a disposable git worktree through a small set of policy-checked tools. Your checkout is never touched. |
179
+ | 5 | **Verify** | The checks below run independently of the agent. |
180
+ | 6 | **Ship** | OpenFix writes `patch.diff`, `receipt.json` and SARIF `fixes[]`. A verified `autofix` can become a draft PR. |
181
+
182
+ ### The checks
183
+
184
+ <img alt="How OpenFix proves a fix. Each check runs on the original code and then on the patched code. Rescan: your scanner reports the finding before, and it is gone with nothing new after, so the fix removed the real finding. Tests: a baseline is recorded before, and the suite does no worse after. Regression test, the key check: the test the model wrote must fail on the original code and pass with the fix, so it really exercises the bug. Review, optional: a second model approves the diff. If every required check passes the fix is verified and can become a draft PR; if any fails you get the patch and evidence only. The model is never asked whether it worked." src="https://raw.githubusercontent.com/markusweldon/openfix/main/docs/assets/proof-dark.svg" width="100%">
185
+
186
+ | Check | What it proves |
187
+ |---|---|
188
+ | **Rescan** | The scanner reports the finding on the original code, **and** doesn't report it (or anything new) on the patched code. |
189
+ | **Tests** | Your test suite does no worse on the patched code than on the original. |
190
+ | **Regression test** | The test the agent added **fails on the original code and passes with the fix**, so it actually exercises the vulnerability. |
191
+ | **Review** *(optional)* | A second model, ideally from another provider, reads the exact diff, looking for bypasses and behavior changes. |
192
+
193
+ ### The receipt
194
+
195
+ Each receipt is an [in-toto](https://in-toto.io) statement whose subject is the SHA-256 of `patch.diff`. It records the finding, the policy decision, the model and token cost, and the evidence for every check. Sign it with `--sign` (Sigstore cosign), and re-check it at any time:
196
+
197
+ ```bash
198
+ openfix receipt verify .openfix/runs/<timestamp>/<finding-id> --repo .
199
+ ```
200
+
201
+ <img alt="An OpenFix receipt. receipt.json is an in-toto Statement v1 holding: the subject, sha256 of patch.diff; the finding; the policy decision and the policy's hash; the base commit; the author model, turns and cost; and the checks with their commands, exit codes and output. An optional receipt.sigstore.json signature comes from --sign. openfix receipt verify re-checks that it is a valid statement, that patch.diff matches the digest, that the base commit exists, and that the patch still applies." src="https://raw.githubusercontent.com/markusweldon/openfix/main/docs/assets/receipt-dark.svg" width="100%">
202
+
203
+ ## Policy as code
204
+
205
+ ```yaml
206
+ # openfix.yaml (the first matching rule wins)
207
+ rules:
208
+ - match: { category: [secrets] }
209
+ action: skip # rotate credentials; don't just delete them from code
210
+ - match: { path: ["**/auth/**", "**/payment*/**"] }
211
+ action: propose # patch + receipt for a human, no PR
212
+ - match: { category: [sast, sca], min_severity: medium }
213
+ action: autofix # draft PR when every required check passes
214
+ guards:
215
+ max_files_changed: 4
216
+ max_lines_changed: 200
217
+ protected_paths: [".github/workflows/**", "**/.env*"]
218
+ models:
219
+ author: anthropic:claude-opus-5-5
220
+ reviewer: openai:gpt-5
221
+ local_only_paths: ["services/payments/**"] # this code is only ever sent to local models
222
+ budgets: { max_turns: 40, max_usd_per_fix: 3.0, max_usd_per_run: 25.0 }
223
+ verify:
224
+ require: [rescan, tests, regression_test]
225
+ ```
226
+
227
+ Run `openfix init` to write a starter file. Full reference: [docs/policy.md](https://github.com/markusweldon/openfix/blob/main/docs/policy.md).
228
+
229
+ ## Bring any model
230
+
231
+ | Provider | Example `--model` | Credential |
232
+ |---|---|---|
233
+ | Anthropic | `anthropic:claude-opus-5-5` | `ANTHROPIC_API_KEY` |
234
+ | OpenAI | `openai:gpt-5` | `OPENAI_API_KEY` |
235
+ | Google Gemini | `gemini:gemini-2.5-pro` | `GEMINI_API_KEY` |
236
+ | xAI Grok | `xai:grok-4` | `XAI_API_KEY` |
237
+ | OpenRouter, Groq, DeepSeek, Mistral, Together, Fireworks | `openrouter:<model>`, `groq:<model>`, … | `<PROVIDER>_API_KEY` |
238
+ | Any OpenAI-compatible gateway | `compat:<model>` | `OPENFIX_COMPAT_BASE_URL` |
239
+ | Local: Ollama, vLLM, LM Studio | `ollama:qwen2.5-coder:32b` | none |
240
+
241
+ Run `openfix providers` to see which credentials are set. Details: [docs/providers.md](https://github.com/markusweldon/openfix/blob/main/docs/providers.md).
242
+
243
+ ## GitHub Action
244
+
245
+ ### Run it on a schedule
246
+
247
+ Put OpenFix on a schedule and it works as a remediation factory: your scanners' findings go in, and verified draft PRs come out. Nothing ships without proof, and a person still merges every fix. The workflow below runs every Monday at 06:00 UTC, and you can also start it by hand from the Actions tab. `max` caps how many findings one run attempts, and `max_usd_per_run` in [`openfix.yaml`](https://github.com/markusweldon/openfix/blob/main/docs/policy.md) caps what a run can spend on the model.
248
+
249
+ <img alt="OpenFix on a schedule. 1 Schedule: cron every Monday, or run it by hand. 2 Scan: Snyk, Semgrep, CodeQL or Trivy write SARIF. 3 Fix and verify: policy decides, the model patches, code proves it, within max and max_usd_per_run. 4 Draft PRs: one per verified fix, with an evidence table and the receipt digest, never auto-merged. 5 You merge: your CI runs and a person reviews and decides. The next run updates the same PR branch instead of opening a duplicate. Every run uploads receipts, summary.md and openfix.sarif as a workflow artifact." src="https://raw.githubusercontent.com/markusweldon/openfix/main/docs/assets/schedule-dark.svg" width="100%">
250
+
251
+ ```yaml
252
+ name: OpenFix
253
+ on:
254
+ workflow_dispatch:
255
+ schedule: [{ cron: "0 6 * * 1" }]
256
+ permissions:
257
+ contents: write
258
+ pull-requests: write
259
+ jobs:
260
+ fix:
261
+ runs-on: ubuntu-latest
262
+ steps:
263
+ - uses: actions/checkout@v4
264
+ - run: pip install semgrep && semgrep scan --config p/default --sarif -o semgrep.sarif || true
265
+ - uses: markusweldon/openfix@v0.4.0
266
+ with:
267
+ reports: semgrep.sarif
268
+ model: anthropic:claude-opus-5-5
269
+ reviewer: openai:gpt-5
270
+ env:
271
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
272
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
273
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
274
+ ```
275
+
276
+ Each verified autofix becomes a draft PR with an evidence table and the receipt digest. Receipts, `summary.md` and `openfix.sarif` are uploaded as a workflow artifact. Your CI still runs on the PR, and a person still merges it.
277
+
278
+ ## Supported inputs
279
+
280
+ | Format | Sources |
281
+ |---|---|
282
+ | SARIF 2.1.0 | Semgrep, CodeQL, Snyk Code, Trivy, Checkov, Bandit, Gitleaks, … |
283
+ | Native JSON | Semgrep, Snyk Open Source, Trivy (vulnerabilities, misconfigurations, secrets), OSV-Scanner, Gitleaks |
284
+ | GitHub APIs | Code-scanning alerts, Dependabot alerts |
285
+ | OpenFix | [Findings JSON](https://github.com/markusweldon/openfix/blob/main/docs/findings-format.md), for your own tools |
286
+
287
+ Formats are detected automatically. Pass several reports at once and duplicate findings are merged.
288
+
289
+ ## Commands
290
+
291
+ | Command | |
292
+ |---|---|
293
+ | `openfix findings REPORT...` | Normalize and list findings (`--json` for OpenFix findings JSON) |
294
+ | `openfix plan REPORT...` | Show the policy decision for each finding |
295
+ | `openfix fix REPORT...` | Fix, verify and write receipts: `--model`, `--reviewer`, `--only`, `--max`, `--require`, `--sandbox`, `--open-prs`, `--sign` |
296
+ | `openfix receipt verify DIR` | Re-check a receipt's digests and that its patch still applies |
297
+ | `openfix providers` | Supported providers and credential status |
298
+ | `openfix init` | Write a starter `openfix.yaml` |
299
+
300
+ `--repo` can point at a subdirectory of a monorepo. Findings, tests and scans are resolved relative to it, and patches are written relative to the repository root.
301
+
302
+ ## Documentation
303
+
304
+ - [Policy reference](https://github.com/markusweldon/openfix/blob/main/docs/policy.md)
305
+ - [Providers and models](https://github.com/markusweldon/openfix/blob/main/docs/providers.md)
306
+ - [Verification and receipts](https://github.com/markusweldon/openfix/blob/main/docs/receipts.md)
307
+ - [Security model](https://github.com/markusweldon/openfix/blob/main/docs/security-model.md): what OpenFix protects against, and what it doesn't
308
+ - [Findings format](https://github.com/markusweldon/openfix/blob/main/docs/findings-format.md)
309
+ - [Brand and diagrams](https://github.com/markusweldon/openfix/blob/main/docs/brand/README.md): logo, colours, type, and the script that draws the images
310
+ - [Roadmap](https://github.com/markusweldon/openfix/blob/main/ROADMAP.md)
311
+
312
+ ## Status
313
+
314
+ OpenFix 0.3 is **alpha**. The core pipeline (ingest, policy, agent, verification, receipts and PRs) is implemented and tested end to end against real scanners and test suites. Next on the [roadmap](https://github.com/markusweldon/openfix/blob/main/ROADMAP.md): a public fix-rate benchmark across models, an MCP server, and GitLab support.
315
+
316
+ Issues and pull requests are welcome; start with [CONTRIBUTING.md](https://github.com/markusweldon/openfix/blob/main/CONTRIBUTING.md). To report a vulnerability in OpenFix itself, see [SECURITY.md](https://github.com/markusweldon/openfix/blob/main/SECURITY.md).
317
+
318
+ ## License
319
+
320
+ [MIT](https://github.com/markusweldon/openfix/blob/main/LICENSE)
321
+
322
+ <sub>Brand icons in the diagrams come from [Simple Icons](https://simpleicons.org) (CC0) and the [Semgrep repository](https://github.com/semgrep/semgrep). All trademarks belong to their owners, and their use here doesn't imply endorsement.</sub>
@@ -0,0 +1,33 @@
1
+ openfix/__init__.py,sha256=ZdzcefHCrbXxLVrCewkt1ZNEu10P0V4YDPvwMR--e98,103
2
+ openfix/cli.py,sha256=Dw8omiaLpZ_7vVBBtTdoMEJTB-BwHHUirO4ep22-fyg,8490
3
+ openfix/console.py,sha256=idKJSdN5dbvURMW923vhbOMeowZINWt3NRwZFDnAN9M,2477
4
+ openfix/deps.py,sha256=27SErjddeAO8oNZuYiQGAt2-bh1ysUqDFrjkjrcKERc,4398
5
+ openfix/engine.py,sha256=c2Oxj9wqJje-8oohaypx8n9NOYOR96AheFgm6un3uMc,21163
6
+ openfix/findings.py,sha256=DCh4TiKesLIlv9hANUNyrYnKHJer0MqFCUQ37QofUoY,4428
7
+ openfix/github.py,sha256=8kpfcSUH2cWc7oKjRLEfW0D73W2xpLnONvaT-Bvsabw,3463
8
+ openfix/gitutil.py,sha256=_p2jOqjBhRx6ctYrDUUbxN5YMmn8xHydVVWAkveiE1w,3459
9
+ openfix/ingest.py,sha256=PCFwfTz-mtDpRAnYJl-2kMt6UK9mMKIGhh5fvEQ9p2o,21786
10
+ openfix/policy.py,sha256=LmWP0N7DiX1ERsIgrOOJPpi4tDNPmlGak-T_o8I188Y,11335
11
+ openfix/pricing.py,sha256=ZzC2gsPqwe7ClhCm6cYRH5d7i4wIr2e725ez7Hvz5Uk,1434
12
+ openfix/receipt.py,sha256=9p3p-CkjjuM2rE2zDZKpzFBODFvEr0YzdWkUrY5YFuw,5451
13
+ openfix/redact.py,sha256=lJ2DEQf8Ox-hlOBqy0nTVL09j1akoLOBL4K7gVqd-2I,1762
14
+ openfix/report.py,sha256=fLzwzuZcEig0lXrMfReGV_iYz_BPCdmnvYd_lIKt3J4,3371
15
+ openfix/sandbox.py,sha256=bCYBbNbWcvwe2rSQp9A5GJ6N4EOsBvUwhEI4f_lwj44,7366
16
+ openfix/sarif_out.py,sha256=ECwssrSHQwA7VgHCrqRhm580wTzT9tTFH2RNp1kD2VQ,2934
17
+ openfix/scanners.py,sha256=Ax5Wc4w5RADv4XpYJmSicwsXis60D7n2VGncmIyODXc,7173
18
+ openfix/verify.py,sha256=K-9hZCz9o5DPMDc0xe9pExUCvyegYzQ4J-ix-HjT-Qk,10774
19
+ openfix/agent/__init__.py,sha256=KIk9H_x2bHnc3E0Z5bTnXss6Bs1Eqq-jpDnFc2gPYpQ,159
20
+ openfix/agent/loop.py,sha256=QPadBttcTxGaCW_ouQHLwedPk24_76UXwfE1M87l6u4,4272
21
+ openfix/agent/prompts.py,sha256=L3ZzxtLvL15woiNwp_KKBmhQuO5AozKIWzEgNMhDaxk,3500
22
+ openfix/agent/tools.py,sha256=qTa4FeZ0FgnwukO4BQy3y_J34MF-L7kQxuMa0XJy9nA,14836
23
+ openfix/providers/__init__.py,sha256=DINvuJA6otx5ItIyPWtldTcn9J0_i0Qku5AWWeDS0CY,3672
24
+ openfix/providers/anthropic.py,sha256=RhBFt7hUKgEOxwHV9IlMlSjcGuN3Wg10PmYs72M809Q,5008
25
+ openfix/providers/base.py,sha256=km-GY_lMfD_tvkj0tCURmrjjU6fbvAWu1UtO9dU3fHU,2159
26
+ openfix/providers/gemini.py,sha256=u34WF1o1JqZGY-oeP-8drZsltp8oY2KeAd5vMeKMsdo,3435
27
+ openfix/providers/openai_compat.py,sha256=Ip5prvbluT4bQ7-9IOQsseR-R0aDgVMkVyMkM5bJzPk,6730
28
+ openfix/providers/scripted.py,sha256=RBB122crBhIv73aL9ui4rBE-j8LbfyG2llfWcD_pLTc,3241
29
+ openfix_cli-0.4.0.dist-info/METADATA,sha256=nUV0UYEit5wEnJlBjq9AgHG3-zaIcKcAwadkePBWdiQ,18888
30
+ openfix_cli-0.4.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
31
+ openfix_cli-0.4.0.dist-info/entry_points.txt,sha256=_96sg93P884DEA3BQq3f-UjNAbNnE7fBrRszjz2tTvM,45
32
+ openfix_cli-0.4.0.dist-info/licenses/LICENSE,sha256=Iww-qlbcWhvkKDeIvDxB16nn3M_Be_RPRVdkfAbexag,1070
33
+ openfix_cli-0.4.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ openfix = openfix.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Markus Weldon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.