Metadata-Version: 2.4
Name: audit-autopilot
Version: 0.1.0
Summary: Domain-agnostic automated audit batching, strict schema validation, isolated candidate label management, and anonymized regression test generation.
Author: audit-autopilot contributors
License: MIT
Keywords: audit,evaluation,regression-testing,anonymization,cli
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# audit-autopilot

A domain-agnostic, zero-dependency Python 3.10+ toolkit for automated audit batch selection, pluggable audit execution with strict schema and hash verification, isolated candidate label storage, controlled label promotion, and anonymized regression test scaffold generation.

## Key Capabilities

- **Batch Selection**: Reads candidate pool JSON (compatible with ranker/sampler outputs) and selects up to `N` unaudited, single-blocker records that include required artifacts per reason bucket, while tracking missing-evidence counts by bucket.
- **Pluggable Audit Adapters**: Includes an `AuditAdapter` protocol, a deterministic `MockAuditAdapter` for local runs and testing, and a `SubprocessJsonAdapter` for integrating external audit workers over stdin/stdout JSON.
- **Tampering & Prompt-Injection Defense**: Enforces strict JSON schema validation (`expected_action` in `submit`, `hold`, `unsupported`; non-empty `root_cause_category`; `field_values` dict; `evidence` string; strict `sha256` equality with the input record; rejection of unexpected keys). Invalid or tampered responses are safely rejected without crashing the batch.
- **Strict Label Isolation**: Writes newly audited results exclusively to an isolated `candidate_labels.json` file and never modifies `production_labels.json` during audit runs.
- **Controlled Promotion**: Provides a `promote` subcommand that defaults to `--dry-run` (showing added/updated/unchanged diffs) and requires explicit `--approve` to merge selected candidates into a target production labels file.
- **Anonymized Regression Test Generation**: When `>= 3` audited candidates share the same `root_cause_category`, replaces entity names, store names, phone numbers, registration IDs, emails, and raw amounts with deterministic placeholders (`ENTITY_001`, `STORE_001`, `000-0000-0000`, `1000`, etc.), generates a `layout_of(...)` style `unittest` scaffold, and verifies zero PII leakage via `check_no_pii_leak`.

## Installation

Requires Python 3.10+ with zero third-party runtime dependencies.

```bash
pip install -e .
```

Or run directly from source:

```bash
PYTHONPATH=src python -m audit_autopilot.cli --help
```

## CLI Usage

### 1. Run an audit batch

```bash
audit-autopilot run \
  --pool candidate_pool.json \
  --candidate-labels candidate_labels.json \
  --production-labels production_labels.json \
  --max-per-bucket 5 \
  --adapter mock \
  --tests-dir generated_tests \
  --format table
```

Use `--format json` to emit the structured run summary JSON (`audited_count`, `rejected_count`, `by_root_cause`, `pending_promotion_count`, `generated_test_files`, `missing_evidence_by_bucket`).

### 2. Preview and promote candidate labels

Preview diff (default dry-run, never modifies the target file):

```bash
audit-autopilot promote \
  --candidate-labels candidate_labels.json \
  --production-labels production_labels.json \
  --format table
```

Apply promotion explicitly:

```bash
audit-autopilot promote \
  --candidate-labels candidate_labels.json \
  --production-labels production_labels.json \
  --approve
```

Filter to specific records with repeatable `--record-id`:

```bash
audit-autopilot promote \
  --candidate-labels candidate_labels.json \
  --production-labels production_labels.json \
  --record-id rec-001 \
  --record-id rec-002 \
  --approve
```

### 3. Generate anonymized regression tests from candidate labels

```bash
audit-autopilot generate-tests \
  --candidate-labels candidate_labels.json \
  --output-dir generated_tests \
  --min-cluster-size 3 \
  --format json
```

## Running Tests

```bash
PYTHONPATH=src python -m unittest discover -s tests -v
```

## Project Structure

```text
src/audit_autopilot/
  __init__.py      Public package exports
  models.py        Typed dataclasses for records, results, summaries, and diffs
  adapters.py      AuditAdapter protocol, strict validator, MockAuditAdapter, SubprocessJsonAdapter
  anonymizer.py    Deterministic anonymizer, PII leak verifier, unittest scaffold generator
  pipeline.py      Batch selector, isolated label persistence, end-to-end runner
  promote.py       Dry-run diffing and explicit-approval promotion logic
  cli.py           Command-line interface (run, promote, generate-tests)
  py.typed         PEP 561 type marker
docs/
  REQUIREMENTS.md  Functional and safety requirements specification
tests/
  test_pipeline.py     End-to-end pipeline, isolation, validation, and promotion tests
  test_sanitization.py Repository hygiene and confidentiality checks
```
