Metadata-Version: 2.2
Name: egressai
Version: 0.1.3
Summary: Local-first redaction engine for AI egress security
Author-email: EgressAI <security@egressai.dev>
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Topic :: Security
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: egressai-detect-secrets>=1.5.1
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"

# EgressAI

EgressAI is a local-first redaction engine for AI egress security.

The first package takes text, detects secrets, replaces them with stable placeholders, and returns
structured findings without exposing plaintext secret values in the public result.

## Install

```bash
pip install egressai
```

The package depends on `egressai-detect-secrets` for provider-aware secret detection.

## Python API

```python
from egressai import RedactionEngine

secret = "sk-proj-" + "a" * 40
result = RedactionEngine().redact(f"OPENAI_API_KEY={secret}")
print(result.redacted_text)
```

Output:

```text
OPENAI_API_KEY={{EGRESSAI_SECRET_OPENAI_001}}
```

Restore redacted text during the same engine session:

```python
engine = RedactionEngine()
result = engine.redact(f"OPENAI_API_KEY={secret}")
restored = engine.restore(result.redacted_text)
```

The restore map is memory-only and is not included in structured output.

Structured result:

```python
payload = result.to_dict()
```

The structured output includes:

- `redacted_text`
- `findings`
- `stats`

Each finding includes zero-based character offsets (`start`, `end`) plus
one-based `line` and `column` metadata for locating the sensitive value in files,
logs, and pasted diffs.

Plaintext secret values are not included in `result.to_dict()`.

## CLI

Redact inline text:

```bash
egressai redact "OPENAI_API_KEY=sk-proj-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
```

Redact a file:

```bash
egressai redact ./prompt.txt
```

Redact stdin:

```bash
cat ./logs.txt | egressai redact
```

Existing file paths are read from disk. Any other input is treated as literal text,
including large multi-line contexts passed as one argument. For very large prompts
or logs, stdin is usually the most reliable shell interface.

Return the full redaction result as JSON:

```bash
egressai redact --json ./sample.env
```

Scan without printing redacted text:

```bash
egressai scan ./sample.env
```

Return findings and stats as JSON:

```bash
egressai scan --json ./sample.env
```

Return one finding per JSON Lines record:

```bash
egressai scan --jsonl ./sample.env
```

Fail when findings are present:

```bash
egressai scan --fail-on-findings ./sample.env
```

Use a custom placeholder prefix:

```bash
egressai redact --placeholder-prefix SAFE ./prompt.txt
```

## Exit Codes

By default, CLI commands exit `0` even when findings are detected.

With `--fail-on-findings`:

- exits `0` when no findings are detected
- exits `1` when findings are detected
- exits `2` for CLI usage errors

## Supported Secret Types

Initial support includes:

- OpenAI API keys
- Anthropic API keys
- Google/Gemini API keys
- GitHub tokens
- GitLab tokens
- AWS access keys
- Stripe keys
- Slack tokens
- npm tokens, including `.npmrc` auth tokens and `NPM_TOKEN=npm_...` env values
- PyPI tokens
- Hugging Face tokens
- JWTs, including JWT-like tokens with non-base64url signature suffixes
- private key blocks
- database URLs, including JSON-escaped URL values such as `postgres:\/\/...`
- Azure connection strings
- generic `.env`-style secret assignments

Provider mappings are covered by tests so each supported detector returns the
expected EgressAI type, detector name, and placeholder subtype.

The test suite includes a messy real-world fixture with a pasted user report,
code diff, curl commands, runtime env vars, JSON payloads, repeated secrets, and
multiple provider token types.

## Release Notes

### 0.1.3

- Added finding `line` and `column` metadata.
- Added same-session restore support through `RedactionEngine.restore()`.
- Added a messy real-world fixture corpus.
- Added JSON-escaped database URL redaction.
- Added `egressai scan --jsonl`.

## Maintainer Notes

Every user-visible change should update this README in the same change set.

Before publishing:

```bash
python3 -m pytest
python3 -m build
python3 -m twine check dist/egressai-*
```
