Metadata-Version: 2.4
Name: integrity-evidence-gate
Version: 0.1.2
Summary: Digest-bound test execution cache and rate-limited monitor gate for autonomous AI coding agents.
Author: BlackBadHope
License: MIT
Project-URL: Homepage, https://integrityharness.dev
Project-URL: Repository, https://github.com/BlackBadHope/evidence-gate
Project-URL: Issues, https://github.com/BlackBadHope/evidence-gate/issues
Keywords: ai-agents,claude-code,codex,cursor,testing,evidence,ci,governance
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
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
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="docs/assets/hero-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="docs/assets/hero-light.svg">
    <img src="docs/assets/hero-light.svg" alt="evidence-gate — SHA-256 digest-bound test cache and anti-loop monitor gate" width="100%">
  </picture>
</p>

<h1 align="center">evidence-gate</h1>
<p align="center"><b>SHA-256 digest-bound test execution ledger &amp; anti-loop monitor gate — zero wasted re-runs on unchanged trees.</b></p>

<p align="center">
  <a href="https://github.com/BlackBadHope/evidence-gate/actions/workflows/ci.yml"><img src="https://github.com/BlackBadHope/evidence-gate/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
  <a href="https://pypi.org/project/integrity-evidence-gate/"><img src="https://img.shields.io/pypi/v/integrity-evidence-gate.svg" alt="PyPI"></a>
  <img src="docs/assets/badge-python.svg" alt="Python 3.10+">
  <img src="docs/assets/badge-deps.svg" alt="0 stdlib deps">
  <img src="docs/assets/badge-tests.svg" alt="35 tests">
  <img src="docs/assets/badge-platforms.svg" alt="Win / Linux / macOS">
  <a href="LICENSE"><img src="docs/assets/badge-license.svg" alt="MIT License"></a>
</p>

<p align="center">
  <a href="#quick-start">Quick Start</a> ·
  <a href="#live-demo">Live Demo</a> ·
  <a href="#architecture">Architecture</a> ·
  <a href="#evidence-ladder-e0e4">Evidence Ladder</a> ·
  <a href="#core-commands">Core Commands</a> ·
  <a href="#guarantee--threat-model">Threat Model</a> ·
  <a href="#integrity-harness-ecosystem">Ecosystem</a>
</p>

---

Autonomous coding agents burn **30–60% of their context window and API budget** re-running identical passing test suites and polling unchanged CI/deploy logs in tight loops. `evidence-gate` stops both deterministically with **SHA-256 digest-bound PASS reuse** and a **rate-limited, loop-breaking monitor FSM** — pure Python 3.10+ stdlib (**zero runtime dependencies, `shell=False` always**).

> [!WARNING]
> **Critical PyPI package-name warning:** Do **NOT** run `pip install evidence-gate`. The unscoped `evidence-gate` name on PyPI is owned by an unrelated third party (`blazingRadar`). The official PyPI distribution for this repository is **`integrity-evidence-gate`** (which provides the `evidence-gate` CLI command and the `evidence_gate` Python module).

---

## Quick Start

**1-line zero-friction usage** — auto-defaults to `--kind targeted`, `--reason cli-run`, deterministic `--suite-id auto-<sha256>`, and the current directory as watched artifact. Run `evidence-gate status` (or zero-arg `evidence-gate`) to inspect your local ledger anytime.

### Linux / macOS (`bash`)

```bash
# Option 1: Isolated CLI Install via pipx (ALWAYS `integrity-evidence-gate`, NEVER `evidence-gate`)
pipx install integrity-evidence-gate
evidence-gate run -- pytest

# Option 2: Zero-install ephemeral run via uvx
uvx --from integrity-evidence-gate evidence-gate run -- pytest

# Option 3: Isolated .venv via pip
python3 -m venv .venv
.venv/bin/python -m pip install integrity-evidence-gate
.venv/bin/evidence-gate run -- pytest

# Option 4: Zero-install standalone script from source (pure Python 3.10+ stdlib)
python3 agensi-skill-pack/evidence-test-gate/scripts/evidence_test.py -- pytest
```

### Windows (`pwsh 7`)

```powershell
# Option 1: Isolated CLI Install via pipx (ALWAYS `integrity-evidence-gate`, NEVER `evidence-gate`)
pipx install integrity-evidence-gate
evidence-gate run -- pytest

# Option 2: Zero-install ephemeral run via uvx
uvx --from integrity-evidence-gate evidence-gate run -- pytest

# Option 3: Isolated .venv via pip
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install integrity-evidence-gate
.\.venv\Scripts\evidence-gate.exe run -- pytest
```

---

## Live Demo

Verified CLI capture showing a cold `EXECUTED` run, an immediate warm `SKIP_CACHED_PASS` hit (`command_calls=0`, `0 ms`), and `evidence-gate status`:

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="docs/assets/demo-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="docs/assets/demo-light.svg">
    <img src="docs/assets/demo-light.svg" alt="evidence-gate verified CLI capture" width="100%">
  </picture>
</p>

---

## Architecture

<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="docs/assets/architecture-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="docs/assets/architecture-light.svg">
    <img src="docs/assets/architecture-light.svg" alt="evidence-gate SHA-256 digest and anti-loop monitor architecture" width="100%">
  </picture>
</p>

### Key Mechanical Properties

- **Zero runtime dependencies** — pure Python 3.10+ standard library.
- **Digest-bound PASS reuse (`run`):** hashes target files/directories (symlink-safe SHA-256, ignoring `.git`/`__pycache__`/`node_modules`), OS/Python environment fingerprint, and exact command argv. If an identical PASS already exists in the append-only JSONL ledger, returns `SKIP_CACHED_PASS` in milliseconds with `command_calls=0`.
- **Fail-safe invalidation:** failed runs are never cached; any 1-byte change in any watched artifact invalidates the key immediately; `--force` requires an explicit `--force-reason` audit trail.
- **Bounded monitor polling (`observe`):** enforces `--min-interval-seconds`, `--deadline-utc`, and `--max-unchanged` consecutive identical-output loop breaking (`STOP_UNCHANGED`, `STOP_DEADLINE`, `SKIP_TOO_SOON`).
- **Concurrency & integrity:** atomic `O_CREAT | O_EXCL` file lease (`exit 75` on active duplicate run, automatic stale-lock reclamation), atomic `os.replace` state updates, `0o600`/`0o700` private permissions, `shell=False` always.

---

## Evidence Ladder (E0–E4)

Pair `evidence-gate` with a progressive verification budget so agents start with the smallest proving gate instead of running full suites on every edit:

| Level | `--kind` | Typical scope | Freshness default |
| :--- | :--- | :--- | :--- |
| **E0** | `static` | Linter / typecheck / schema check on edited files | `artifact` |
| **E1** | `targeted` | Single failing/changed unit test module | `artifact` |
| **E2** | `impacted` | Affected package test suite | `artifact` |
| **E3** | `smoke` / `replay` | End-to-end smoke or fixture replay | `ttl` or `artifact` |
| **E4** | `full` | Full repository suite before release/PR | `artifact` |

---

## Core Commands

### 1. Digest-bound test gate (`run`)

```bash
# Zero-flag 1-liner: cold run -> EXECUTED, immediate repeat -> SKIP_CACHED_PASS (0 command calls)
evidence-gate run -- pytest
python3 agensi-skill-pack/evidence-test-gate/scripts/evidence_test.py -- pytest

# Full explicit form: narrow watched artifacts and record audit metadata
evidence-gate run \
  --kind targeted \
  --suite-id auth-unit \
  --reason "verify token parser fix" \
  --artifact src/auth \
  --artifact tests/test_auth.py \
  -- python -m unittest tests/test_auth.py

# Second run with unchanged artifacts -> instant SKIP_CACHED_PASS (0 command calls, 1-line summary)
evidence-gate run \
  --kind targeted \
  --suite-id auth-unit \
  --reason "re-check before commit" \
  --artifact src/auth \
  --artifact tests/test_auth.py \
  -- python -m unittest tests/test_auth.py

# Force a fresh run with mandatory audit reason
evidence-gate run \
  --kind smoke \
  --suite-id api-health \
  --reason "post-restart verification" \
  --freshness volatile \
  --force --force-reason "container restarted externally" \
  -- python scripts/smoke_check.py
```

### 2. Rate-limited, loop-breaking monitor (`observe`)

```bash
# Take at most 1 sample every 60s, stop after 3 identical outputs or after deadline
evidence-gate observe \
  --monitor-id deploy-rollout \
  --reason "watch staging rollout" \
  --deadline-utc 2026-12-31T23:59:59Z \
  --min-interval-seconds 60 \
  --max-unchanged 3 \
  --json \
  -- python scripts/check_rollout.py
```

### 3. Local ledger status (`status`)

```bash
evidence-gate status
```

### Exit Codes

| Exit code | Meaning |
| :--- | :--- |
| `0` | Command passed, `SKIP_CACHED_PASS`, `SKIP_TOO_SOON`, or `STOP_DEADLINE` |
| `2` | `PolicyError` (nonexistent `--artifact`, `--force` without `--force-reason`, invalid TTL/cwd/command) |
| `75` | `BusyError` (`SKIP_BUSY` — an identical run/monitor already holds the `FileLease`) |
| `<rc>` | Underlying command's non-zero exit code (with compact `failure_tail:` on stdout) |

---

## Guarantee & Threat Model

- **What `evidence-gate` guarantees:** deterministic SHA-256 key binding over declared `--artifact` paths + OS/Python/cwd + command argv; append-only JSONL audit ledger; zero shell injection (`shell=False`); strict concurrency exclusion via `O_CREAT | O_EXCL`.
- **Boundary you must respect:** if a test depends on external mutable state (live database, remote API, clock, undeclared config file), either pass the config as an `--artifact`, use `--freshness ttl --ttl-seconds N`, or mark it `--freshness volatile`. The gate can only hash what you declare.
- State defaults to `~/.evidence-gate` (override via `EVIDENCE_GATE_HOME` or `--ledger`/`--logs-dir`/`--state-dir`).

---

## Development & Verification

```bash
ruff check evidence_gate evidence_gate_cli.py tests agensi-skill-pack
python -m pytest -q
# or unittest:
python -m unittest discover -s tests -p "test_*.py" -v
```

---

## Integrity Harness Ecosystem

| Repository | Role in the Harness | Stack |
| :--- | :--- | :--- |
| [BlackBadHope/agent-killswitch](https://github.com/BlackBadHope/agent-killswitch) | OS process-tree killswitch & runaway execution breaker | Python stdlib · Win32 / POSIX |
| [BlackBadHope/agent-token-forensics](https://github.com/BlackBadHope/agent-token-forensics) | Read-only JSONL token, cache-cliff & retry-loop forensics | Python 3.10+ stdlib · MCP |
| **[BlackBadHope/evidence-gate](https://github.com/BlackBadHope/evidence-gate)** | **SHA-256 digest-bound test cache & anti-loop monitor gate** | **Python 3.10+ stdlib · CLI** |
| [BlackBadHope/integrity-platform](https://github.com/BlackBadHope/integrity-platform) | Multi-plane execution firewall, witness ledger & control plane | Go / Python · Hybrid |
| [BlackBadHope/neon-studio](https://github.com/BlackBadHope/neon-studio) | Multi-stage agent studio & CAS patch rail | TypeScript / Python |
| [BlackBadHope/integrity-landing](https://github.com/BlackBadHope/integrity-landing) | Public control-plane site & docs ([integrityharness.dev](https://integrityharness.dev)) | Cloudflare Pages |

## License & Disclaimer

MIT — see [`LICENSE`](LICENSE). Security policy and responsible disclosure: [`SECURITY.md`](SECURITY.md).

> **Independent Open-Source Project:** `evidence-gate` (`integrity-evidence-gate`) is an independent open-source project maintained by BlackBadHope and is not affiliated with, endorsed by, or sponsored by Anthropic, OpenAI, Cursor, Google, or any other AI/IDE vendor referenced for compatibility.
