patchwitness

pangxueyuan2-creator/patchwitness Checked 2 days ago

Independent trust gate for AI coding agents: verify scope, protected CI, real checks, secrets, impact, and portable Change Passports.

AI coding agents can spit out a patch in a few minutes. The hard part is still figuring out whether they stayed in scope, whether they touched CI or their own checks, and whether the tests they claim passed actually ran. PatchWitness tries to answer those questions with real Git data and real process output instead of model claims. It produces a Change Passport — a small evidence pack you can inspect and verify offline. No model is asked to grade its own work.

Summary extracted from the README.

AI coding agents can spit out a patch in a few minutes.
The hard part is still figuring out whether they stayed in scope, whether they touched CI or their own checks, and whether the tests they claim passed actually ran.

PatchWitness tries to answer those questions with real Git data and real process output instead of model claims.

It produces a Change Passport — a small evidence pack you can inspect and verify offline. No model is asked to grade its own work.

This is a local tool, not another AI reviewer.

60-second demo

The demo shows a common failure: the agent adds a correct feature and a passing test, but also weakens a protected CI workflow. Tests pass. PatchWitness still fails the change.

git clone https://github.com/pangxueyuan2-creator/patchwitness.git
cd patchwitness
python demo/run_demo.py

No package install needed. See the demo README and the committed terminal transcript.

Quick start

Structural scan only (no code execution):

uvx --from "https://github.com/pangxueyuan2-creator/patchwitness/releases/download/v0.3.1/patchwitness-0.3.1-py3-none-any.whl" patchwitness scan --no-checks

Or install once:

pipx install "https://github.com/pangxueyuan2-creator/patchwitness/releases/download/v0.3.1/patchwitness-0.3.1-py3-none-any.whl"
# or
uv tool install "https://github.com/pangxueyuan2-creator/patchwitness/releases/download/v0.3.1/patchwitness-0.3.1-py3-none-any.whl"

Then inside any Git repo:

patchwitness doctor          # what it detected
patchwitness scan            # full scan (runs tests)
patchwitness scan --no-checks # structural only

scan compares the working tree against HEAD (or the latest commit if clean). Use --base origin/main when you want an explicit boundary.

What it actually checks

Question How it answers
Did the change stay in scope? Path rules against the real Git diff
Did it touch CI / the verifier itself? Protected rules loaded from a trusted base commit
Did the tests really run? Real process exit code + duration + redacted output hash
What else might break? Local reverse dependency graph
Can I trust this report later? Canonical JSON + SHA-256

A green passport does not mean the code is correct. It only means the recorded scope, policy, checks, and integrity claims hold.

Setting up a policy

Use typed TOML policy values. The strict loader in v0.3.1 rejects quoted booleans and scalar path lists instead of coercing them.

patchwitness init
# look at the generated .patchwitness.toml
git add .patchwitness.toml .gitignore
git commit -m "chore: add PatchWitness policy"

Then enforce against that base:

patchwitness gate --base origin/main --policy-ref origin/main --clean-room

In CI you can use the Marketplace Action.

Commands

patchwitness scan              first look, zero config
patchwitness init              write a starter contract
patchwitness gate ...          enforce and fail closed
patchwitness verify <file>     offline integrity check
patchwitness impact --base HEAD
patchwitness doctor
patchwitness mcp --root .

Exit codes: 0 pass, 1 gate failure, 2 usage/runtime error.

Checks capture at most 1 MiB per output stream and fail on overflow or timeout. See check execution limits for diagnostics and cleanup boundaries.

These answer different questions and do not depend on each other:

  • GuardSpec — before work starts, check the repository’s explicit agent rules against a proposed path or command
  • TaskToPR — turn one Issue into an isolated branch, run real tests, leave evidence, optionally open a PR

Use any combination, or none of them.

The optional Safe Delivery integration composes exact-version evidence from TaskToPR and the static analysis/security tools into JSON, SARIF and a content-addressed receipt. Its local nine-component fixture demo preserves FAIL, REVIEW_REQUIRED and UNKNOWN; it does not authorize unattended releases.

Status

Public alpha (v0.3.x). Evidence schema v1 is stable. Single maintainer. No production claims.

Upgrading from v0.3.0? Read the v0.3.1 migration notes for stricter policy/MCP inputs and corrected Git and SARIF evidence.

Upgrading from v0.2.2? Read the v0.3.0 migration notes, especially the new check-output and evidence-input limits.

Limitations are listed in PROJECT_STATUS.md and the threat model. The important ones:

  • Clean-room is filesystem isolation, not a real security sandbox
  • Dependency graph is conservative, not full compiler-level analysis
  • A passing check only proves the command ran and exited 0

Contributing

See CONTRIBUTING.md. Security reports go to SECURITY.md.

Apache-2.0.