Metadata-Version: 2.4
Name: permitdiff
Version: 0.1.0rc3
Summary: Semantic regression testing and CI gates for AI-agent tool permissions.
Author: Mohammad Atashi
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/TensorScholar/permitdiff
Project-URL: Documentation, https://github.com/TensorScholar/permitdiff#readme
Project-URL: Source, https://github.com/TensorScholar/permitdiff
Project-URL: Issues, https://github.com/TensorScholar/permitdiff/issues
Project-URL: Changelog, https://github.com/TensorScholar/permitdiff/blob/main/CHANGELOG.md
Project-URL: Security, https://github.com/TensorScholar/permitdiff/security/policy
Keywords: ai-agents,mcp,security,policy,permissions,regression-testing,ci
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Security
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: pydantic<3,>=2.10
Requires-Dist: PyYAML<7,>=6.0.2
Requires-Dist: typer<1,>=0.15
Requires-Dist: rich<16,>=13.9
Provides-Extra: dev
Requires-Dist: build<2,>=1.2; extra == "dev"
Requires-Dist: jsonschema<5,>=4.23; extra == "dev"
Requires-Dist: mypy<3,>=1.14; extra == "dev"
Requires-Dist: pip-audit<3,>=2.8; extra == "dev"
Requires-Dist: pre-commit<5,>=4; extra == "dev"
Requires-Dist: pytest<10,>=8.3; extra == "dev"
Requires-Dist: pytest-cov<8,>=6; extra == "dev"
Requires-Dist: ruff<1,>=0.15; extra == "dev"
Requires-Dist: twine<8,>=6; extra == "dev"
Provides-Extra: release
Requires-Dist: cyclonedx-bom<8,>=6; extra == "release"
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/TensorScholar/permitdiff/main/docs/assets/permitdiff-hero.svg" alt="PermitDiff — permission plans for AI agents" width="900">
</p>

<p align="center">
  <strong>Detect when an AI-agent permission change can grant more power.</strong><br>
  Deterministic permission plans and CI gates for tool-calling agents.
</p>

<p align="center">
  <a href="https://github.com/TensorScholar/permitdiff/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/TensorScholar/permitdiff/actions/workflows/ci.yml/badge.svg"></a>
  <a href="https://github.com/TensorScholar/permitdiff/actions/workflows/security.yml"><img alt="Security" src="https://github.com/TensorScholar/permitdiff/actions/workflows/security.yml/badge.svg"></a>
  <a href="https://scorecard.dev/viewer/?uri=github.com/TensorScholar/permitdiff"><img alt="OpenSSF Scorecard" src="https://api.scorecard.dev/projects/github.com/TensorScholar/permitdiff/badge"></a>
  <img alt="Python 3.11–3.14" src="https://img.shields.io/badge/python-3.11%E2%80%933.14-3776AB?logo=python&logoColor=white">
  <a href="LICENSE"><img alt="Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-5B5BD6"></a>
</p>

<p align="center">
  <img src="https://raw.githubusercontent.com/TensorScholar/permitdiff/main/docs/assets/permitdiff-terminal.svg" alt="PermitDiff blocking an approval bypass" width="900">
</p>

## Why PermitDiff

A text diff shows that policy YAML changed. It does **not** tell a reviewer whether the proposed change can materially widen reviewed authority.

PermitDiff evaluates the same review corpus against baseline and candidate policies **and** performs bounded static authority analysis over the policy change. The result separates observed scenario evidence from conservative policy-level findings.

| Detects | Example |
|---|---|
| **Observed privilege expansion** | scenario resolves `deny → allow` |
| **Approval bypass** | `require_approval → allow` |
| **Scope widening** | `payments.refund → payments.*` |
| **Constraint weakening** | `amount <= 100 → amount <= 10000` |
| **Coverage drift** | New rule has no observed scenario |
| **Unsafe defaults** | Fallback becomes more permissive |
| **Precedence uncertainty** | Mixed-effect rules change order |
| **Stale exceptions** | Waiver expired, drifted, or unused |

When bounded static analysis cannot prove a changed construct non-expanding, the result is `unknown` and the strict gate fails closed. PermitDiff does not convert uncertainty into safety.

## Five-minute start

```bash
pipx install git+https://github.com/TensorScholar/permitdiff.git@v0.1.0rc2
permitdiff init permissions && cd permissions
permitdiff compare policies/baseline.yaml policies/candidate.yaml corpus.jsonl \
  --gate permitdiff-gate.yaml
```

Exit `0` = pass · `2` = valid comparison blocked by policy · `1` = invalid input or execution.

## Git-resolved baseline

The post-`v0.1.0rc2` development line can compare the current candidate against a policy stored at an already-fetched Git ref, so a PR workflow does not need to materialize a separate baseline file:

```bash
permitdiff compare \
  permissions/policy.yaml \
  permissions/policy.yaml \
  permissions/corpus.jsonl \
  --baseline-ref origin/main \
  --baseline-evidence-output permitdiff-baseline-source.json \
  --gate permissions/permitdiff-gate.yaml
```

With `--baseline-ref`, the first policy path is resolved from the local Git object database. PermitDiff resolves the requested ref to an exact commit, resolves the policy to an exact blob, enforces the normal policy-size/schema bounds, and reads the blob without checking it out or executing repository code. The evidence file records requested ref, resolved commit, repository-relative policy path, Git object ID, and raw SHA-256. PermitDiff does **not** fetch remotes implicitly; the ref must already be available locally.

Ref syntax is deliberately conservative. Arbitrary Git revision expressions and traversal-style paths are rejected rather than interpreted. The normal semantic report still binds the validated policy through its canonical policy digest; Git-source evidence separately binds where the baseline bytes came from.

## Native Claude Code preapproval projection

The post-`v0.1.0rc2` development line adds a bounded native on-ramp for Claude Code project settings. It projects a documented subset of `permissions.allow` into the same semantic engine used by PermitDiff policies instead of reducing native rules to a text or rank diff.

```bash
permitdiff claude compare \
  .claude/settings.baseline.json \
  .claude/settings.local.json \
  corpus.jsonl \
  --strict \
  --format markdown
```

The initial adapter accepts only explicit `permissions.defaultMode = "dontAsk"` pairs whose `deny` and `ask` rules are unchanged. Bare-tool translation is deliberately limited to `Bash`, `PowerShell`, `WebFetch`, and `WebSearch`; other bare tools remain opaque because their approval semantics can differ. The adapter also translates exact `WebFetch(domain:HOST)` preapprovals, de-noises documented same-effect redundancies such as `Bash(git mv *)` when bare `Bash` is already granted, and fails closed when changed native semantics cannot be represented faithfully.

This is a **preapproval projection, not a complete Claude effective-authority importer**. Non-`permissions` root settings are not modeled; their values are compared through canonical digests while evidence exposes only their key names and identifies which ignored root keys changed. If such root settings differ, comparison stops unless the reviewer explicitly passes `--allow-ignored-root-changes`. That flag acknowledges only that the reviewer wants to analyze the bounded permission projection; it does not approve or waive the ignored changes.

Claude Code's current documentation states that domain-scoped WebFetch rules can also affect sandbox network-domain policy. PermitDiff models exact `WebFetch(domain:HOST)` rules here only as WebFetch preapprovals. If any exact WebFetch-domain declaration changes—even one that is preapproval-redundant beneath bare `WebFetch`—comparison stops unless the reviewer passes `--acknowledge-webfetch-sandbox-gap`. This acknowledgement allows analysis of the preapproval projection only; it is not evidence that sandbox/network consequences were reviewed or accepted.

`WebFetch(domain:*)` is intentionally **not** collapsed into bare `WebFetch`; a changed wildcard-domain rule is unsupported and fails closed because the two forms have different sandbox effects. The public regression pilot also changes `enabledPlugins`, so its two reported expansions are specifically the two modeled `permissions.allow` preapproval expansions—not a claim about the entire settings file.

The adapter also does not model managed/user overrides, hooks, plugin-provided capabilities, built-in exceptions, other permission modes, arbitrary file/path rules, or arbitrary Bash/PowerShell patterns. `WebFetch` domain scenarios use reserved `_claude.permission_domain` review metadata created for normalization; that field is not claimed to be raw Claude tool input.

Use `--evidence-output <path>` when you need the adapter's normalization record. The evidence records declared exact WebFetch domains and whether each projection gap was explicitly acknowledged, but can also contain native permission-rule text and should be treated as potentially sensitive review material rather than automatically published CI output.

## Architecture

```mermaid
flowchart LR
  B[Baseline policy] --> C[Deterministic comparison]
  N[Candidate policy] --> C
  S[Scenario corpus] --> C
  C --> O[Observed transitions]
  C --> A[Bounded static authority findings]
  O --> P[Permission plan]
  A --> P
  P --> G{Release gate}
  G -->|pass| M[Merge]
  G -->|fail| R[Review / exact bounded waiver]
```

- **No LLM in the decision path** — deterministic, local, reproducible.
- **Semantics over text** — rule effects, scopes, constraints, defaults, and precedence matter; descriptions do not grant authority.
- **Two evidence channels** — observed scenario transitions remain distinct from bounded static authority findings.
- **Fail-closed** — invalid inputs and unresolved static semantics do not become `allow` or `pass`.
- **Evidence-first** — policy/corpus digests, action/finding fingerprints, JSON, Markdown, SARIF.
- **Bounded waivers** — observed transitions and policy-level findings require exact, expiring review evidence; all waivers are bound to baseline/candidate digests.

## GitHub Action

The current `v0.1.0rc2` release supports explicit baseline/candidate files:

```yaml
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
  with: { python-version: "3.13" }
- uses: TensorScholar/permitdiff@v0.1.0rc2
  with:
    baseline: permissions/policies/baseline.yaml
    candidate: permissions/policies/candidate.yaml
    corpus: permissions/corpus.jsonl
    gate: permissions/permitdiff-gate.yaml
```

The Action writes a Markdown step summary and a SARIF report for code scanning.

On the post-`v0.1.0rc2` development line, the same Action also accepts `baseline-ref`. A PR integration should use a read-only checkout with full history, resolve the base branch as an already-fetched ref such as `origin/${{ github.base_ref }}`, and use the same repository-relative path for baseline and candidate when the policy is modified in place. The Action surfaces `baseline_commit`, `baseline_object`, and `baseline_evidence` outputs and places resolved provenance ahead of the semantic report in the step summary. Pin a release containing this capability before adopting it in another repository; do not replace a release pin with a moving `main` ref.

## Scope

PermitDiff is a **release-time semantic permission regression gate**. It is not a runtime authorizer, credential broker, sandbox, identity provider, generic behavioral evaluator, or proof of exhaustive authorization safety.

Its observed corpus evidence is effective only for the supplied review scenarios. Its built-in static analyzer is a bounded static declared-authority over-approximation that fails closed on unsupported or ambiguous containment. Neither channel is an exhaustive effective-authority proof, and a clean report does not establish runtime authorization safety. Review the [methodology](docs/methodology.md), [threat model](docs/threat-model.md), and [limitations](docs/limitations.md) before sensitive use.

## Trust & delivery

The release pipeline is configured for Python 3.11–3.14 tests, branch-aware coverage, strict typing, linting, dependency audit, CodeQL, OpenSSF Scorecard, clean-wheel smoke tests, CycloneDX SBOMs, Trusted Publishing, checksums, and GitHub build attestations. The `v0.1.0rc2` release execution completed artifact build, external-repository validation, checksums, artifact attestation, SBOM attestation, and GitHub Release creation. PyPI publication is not yet claimed.

**Commercial adoption:** permission architecture reviews, scenario-corpus design, CI rollout, policy migration, and private adapters. [Engagement model →](docs/commercial-support.md)

`0.1.0rc2` is the latest GitHub release candidate using the versioned `v1alpha1` schema. Mutable `main` advances under a separate development identity after releases; breaking changes remain possible before `v1`.

[Docs](docs/) · [Security](SECURITY.md) · [Contributing](CONTRIBUTING.md) · [Roadmap](ROADMAP.md) · [Citation](CITATION.cff)
