# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.3.7] - 2026-03-25
### Added
- **Developer Tools**: Added `AEGIS_UNMASK_CARDS` environment variable to optionally disable card masking (e.g., `****` default) during local testing and E2E validation.
- **`page_url` parameter for `request_virtual_card`**: Optional parameter that lets the agent pass the current checkout URL. If the CDP browser has no open tabs (e.g., Chrome was restarted mid-session), Aegis auto-opens the URL before injecting. Eliminates the need for manual tab management.
- **`AegisBrowserInjector._find_best_page`**: Searches all browser contexts (not just `contexts[0]`) for a checkout page, preferring URLs containing payment/checkout keywords. Fixes injection failures when Playwright MCP creates pages in a non-default context.
- **`AegisBrowserInjector._open_url_in_browser`**: Opens a URL as a new tab in the CDP browser and waits for the payment form JS to initialise. Used by the `page_url` auto-bridge path.

### Fixed
- **MCP server loads `.env` at startup**: Added `load_dotenv()` call at the top of `mcp_server.py` so environment variables (including `AEGIS_ALLOWED_CATEGORIES`, `AEGIS_AUTO_INJECT`, etc.) are correctly read from `.env` without requiring shell-level exports.
- **Injection failure error message**: Now explains the most likely cause (two separate browser instances) and the fix (`page_url` parameter or `--cdp-endpoint` config), instead of a generic "could not find card fields" message.

### Changed
- **Docs — `--scope global` → `--scope user`**: `global` is not a valid Claude Code scope; corrected to `user` (`~/.claude.json`) in both INTEGRATION_GUIDE.md and INTEGRATION_GUIDE.zh-TW.md.
- **Docs — Setup flow clarified**: One-time setup vs per-session steps are now clearly separated. Agent is responsible for checking/starting Chrome via `aegis-launch`; the `--print-mcp` step is called out as one-time only.
- **Docs — Removed redundant `request_virtual_card` call example**: `page_url` usage is covered by the tool docstring and the system prompt template; the separate doc section was duplicate and aimed at the wrong audience.

## [0.3.6] - 2026-03-25
### Added
- **`aegis-launch` CLI**: One-command Chrome CDP launcher. Auto-discovers Chrome on macOS/Linux/Windows, launches with `--remote-debugging-port` and `--user-data-dir`, polls until ready, and prints the exact `claude mcp add` commands for your machine. Options: `--port`, `--url`, `--profile-dir`, `--print-mcp`.
- **Billing field auto-fill**: `AegisBrowserInjector` now fills billing detail fields (first name, last name, street, zip, email) from `AEGIS_BILLING_*` env vars in the main page frame, in the same CDP pass as card injection. Returns `{"card_filled": bool, "billing_filled": bool}`.

### Fixed
- **`inject_payment_info` return type**: Changed from `bool` to `dict` with `card_filled` and `billing_filled` keys. Backwards-compatible (`bool(result)` still works via truthiness of `card_filled`).
- **Test assertion updated**: `test_injector_no_fields_returns_false` updated to assert the dict return value.

### Changed
- **Docs restructure**: README slimmed to landing page; INTEGRATION_GUIDE promoted to canonical setup reference with Claude Code as §1, `aegis-launch` as primary Step 0 (manual Chrome launch folded into `<details>`).
- **Guardrail mode docs**: Full `keyword` vs `llm` comparison table and LLM config options (OpenAI / Ollama / OpenRouter) moved to INTEGRATION_GUIDE §1 as the single source of truth.

## [0.3.4] - 2026-03-25
### Fixed
- **BYOC Provider Wiring**: `LocalVaultProvider` was not wired into `mcp_server.py`. Real card credentials set via `AEGIS_BYOC_NUMBER` were silently ignored and fell through to `MockStripeProvider`. Added a dedicated BYOC branch to the provider selection logic. Provider priority (high → low): Stripe Issuing → BYOC Local → Mock.

### Added
- **`.env.example`**: Added a full environment variable reference file to the repo root, including all `AEGIS_*` policy variables and the new `AEGIS_BILLING_*` fields.
- **Claude Code Full Setup Guide**: Documented the complete three-component setup for Claude Code (Hacker Edition / BYOC): Chrome CDP launch (`--remote-debugging-port=9222`), Aegis MCP registration with `--project` flag, and Playwright MCP registration with `--cdp-endpoint`. Both MCPs share the same Chrome instance so users can watch the full injection flow live.

## [0.3.3] - 2026-03-23
### Added
- **Browser Automation Layer (`AegisBrowserInjector`)**: Implemented CDP-based cross-origin iframe traversal logic to securely auto-fill real cards for Playwright or browser-use workflows, hiding raw PAN from the agent's context.
- **Optional Dependencies (`[browser]`)**: Added `playwright` directly back into the extra dependencies to streamline installation (`pip install aegis-pay[browser]`).
- **Core Dependencies**: Registered explicitly missing `python-dotenv` for local setups leveraging `LocalVaultProvider`.
- **Scripts Organization**: Moved root `inspect_stripe.py` and `scrape_wiki_donate.py` developer tools to an enclosed `scripts/` directory for cleaner builds.

### Fixed
- **Static Analysis Cleanup**: Removed unused modules like `import asyncio` in `mcp_server.py`, following a Vulture static code analysis pass.

## [0.2.0] - 2026-03-20
### Added
- **Open-Source Framework Support**: Added explicit MCP configuration and integration documentation for **OpenClaw**, **NemoClaw**, Claude Code, and OpenHands.
- **Multilingual Support**: Added Traditional Chinese (`README.zh-TW.md`) documentation alongside the English version.
- **LLM Provider Flexibility**: `LLMGuardrailEngine` now explicitly supports custom `base_url` and `model` parameters, enabling usage of **Ollama**, **vLLM**, OpenRouter, and any OpenAI-compatible API.
- **Dependency Handling**: Split dependencies into optional extras (`[llm]`, `[stripe]`, `[mcp]`, `[langchain]`, `[all]`) to drastically reduce `pip install aegis-pay` bloat for lightweight agents.
- **Dependency Injection**: `AegisClient` now supports injecting a custom `GuardrailEngine` during initialization.
- **Automated Testing**: Added a comprehensive suite of 20 `pytest` cases covering Pydantic models, budget enforcement, providers, and integration logic.

### Changed
- **MCP Configuration**: The MCP Server is now fully controlled via environment variables (`AEGIS_ALLOWED_CATEGORIES`, `AEGIS_MAX_PER_TX`, `AEGIS_MAX_DAILY`, `AEGIS_BLOCK_LOOPS`, `AEGIS_STRIPE_KEY`) instead of hardcoded policies.
- **State Management**: Migrated from unreliable in-memory lists to a robust SQLite (`aegis_state.db`) back-end (`AegisStateTracker`) with persistent connections.
- **Dashboard Data**: The Streamlit Vault Dashboard now reads directly from the live `aegis_state.db` SQLite database rather than mock data.

### Fixed
- **Daily Budget Enforcement**: Fixed an issue where the daily budget cap was not accurately tracking and blocking agent spend across sequential runs.
- **Stripe Provider Exceptions**: Refactored `StripeIssuingProvider` to gracefully catch and return explicit `stripe.StripeError` codes as formal rejection reasons instead of crashing the agent workflow.
- **Cardholder API**: Fixed the Stripe implementation by properly generating a `Cardholder` object before attempting to issue virtual cards.
- **Burn-after-use Security**: Implemented validation to ensure requested execution attempts correctly utilize issued `seal_id` mapping.

## [0.1.0] - Early 2026
### Added
- Initial release of Project Aegis (AgentPay).
- Basic `GuardrailPolicy`, `VirtualSeal`, and `PaymentIntent` Pydantic models.
- Minimal MVP Streamlit Dashboard (The Vault).
- Initial `MockStripeProvider` for testing workflows.
