Metadata-Version: 2.4
Name: autocraft
Version: 0.1.0
Summary: AutoCraft Enterprise — AST-Safe, Git-Native LLM code generation for FastAPI projects.
Project-URL: Homepage, https://github.com/autocraft-ai/autocraft
Project-URL: Documentation, https://github.com/autocraft-ai/autocraft#readme
Project-URL: Repository, https://github.com/autocraft-ai/autocraft
Project-URL: Bug Tracker, https://github.com/autocraft-ai/autocraft/issues
Project-URL: Changelog, https://github.com/autocraft-ai/autocraft/blob/main/CHANGELOG.md
Author: AutoCraft Contributors
License: MIT License
        
        Copyright (c) 2026 AutoCraft Contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ast,autocraft,cli,code-generation,developer-tools,fastapi,llm,mistral,openai
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.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Code Generators
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: litellm>=1.30.0
Requires-Dist: mypy>=1.8.0
Requires-Dist: pydantic>=2.6.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: pyyaml>=6.0.1
Requires-Dist: rich>=13.0.0
Requires-Dist: ruff>=0.3.0
Requires-Dist: typer>=0.9.0
Provides-Extra: dev
Requires-Dist: httpx>=0.27.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://img.shields.io/pypi/v/autocraft?color=blue&label=pypi&logo=python&logoColor=white" alt="PyPI">
  <img src="https://img.shields.io/badge/python-3.11%2B-blue?logo=python&logoColor=white" alt="Python 3.11+">
  <img src="https://img.shields.io/badge/LLM-Mistral%20%7C%20OpenAI%20%7C%20Anthropic-blueviolet" alt="LLM">
  <img src="https://img.shields.io/badge/license-MIT-green" alt="MIT License">
  <img src="https://img.shields.io/badge/code%20style-ruff-black" alt="ruff">
</p>

<h1 align="center">AutoCraft Enterprise</h1>
<p align="center"><b>LLM-powered, AST-safe code generation for FastAPI projects.</b></p>
<p align="center">
  Describe an endpoint in plain English.
  AutoCraft generates the handler, Pydantic schemas, and pytest suite —
  validated, linted, and committed to a dedicated Git branch. Ready to review.
</p>

---

## Why AutoCraft?

| Without AutoCraft | With AutoCraft |
|---|---|
| Write async handler with type hints | Generated automatically, matching your project conventions |
| Define Pydantic v2 request/response schemas | Inferred from your description and existing models |
| Register routes and middlewares | Declared in `autocraft.yaml`, applied automatically |
| Write tests (happy path + edge cases) | Generated as a full pytest-asyncio suite |
| Open API docs and docstrings | Inserted automatically with Args/Returns/Raises |

AutoCraft is **not a chat assistant**. It is a deterministic generation pipeline:
the LLM's output is always AST-validated, ruff-fixed, and Git-branched for human review
before touching your codebase.

---

## Installation

```bash
pip install autocraft
```

Requires **Python 3.11+**.

---

## Quick Start

```bash
# 1 — Set your API key
export MISTRAL_API_KEY=sk-...          # or add to .env

# 2 — Initialise AutoCraft in your project
cd my-fastapi-project
autocraft init                          # creates autocraft.yaml

# 3 — Generate an endpoint
autocraft generate "POST /orders that receives customer_id, product_ids and quantities,
                    validates stock, saves to DB, returns the order with total price"
```

AutoCraft will:

1. **Parse** your description (Mistral extracts method, path, inputs, rules, side-effects).  
2. **Scan** your project via AST (detects existing models, schemas, conventions).  
3. **Generate** handler + schemas + tests using a senior-grade prompt.  
4. **Validate** via `ast.parse` → `mypy` → `ruff --fix`.  
5. **Commit** to a new branch (`autocraft/order-post-<ts>`) — ready for `git diff`.

---

## Generated Output

For `POST /orders`:

```
app/handlers/order.py       ← async FastAPI route with Depends, HTTPException, docstrings
app/schemas/order.py        ← OrderCreate, OrderResponse (Pydantic v2)
tests/test_order.py         ← pytest-asyncio suite with happy path + edge cases
```

Sample generated handler:

```python
@router.post("/orders", status_code=status.HTTP_201_CREATED, response_model=OrderResponse)
async def create_order(
    order_data: OrderCreate,
    db: Annotated[AsyncSession, Depends(get_db)],
    current_user: Annotated[User, Depends(get_current_user)],
) -> OrderResponse:
    """
    Create a new order with the given products and quantities.

    Validates stock availability, calculates total price,
    and persists the order and its line items atomically.

    Args:
        order_data: Customer ID, product IDs, and quantities.
        db: Injected async database session.
        current_user: JWT-authenticated user.

    Returns:
        OrderResponse with id, total_price, and created_at.

    Raises:
        HTTPException 400: mismatched list lengths.
        HTTPException 404: unknown customer or product.
        HTTPException 409: insufficient stock.
    """
```

---

## Configuration (`autocraft.yaml`)

```yaml
version: '1.0'

llm:
  provider: mistral               # mistral | openai | anthropic | azure
  model: mistral/mistral-large-latest
  temperature: 0.2                # low = consistent code
  max_tokens: 4096

context:
  scan_paths:                     # dirs scanned by the AST analyzer
    - app/handlers
    - app/schemas
    - app/models
    - app/services
  max_examples: 3                 # few-shot examples sent to the LLM

generation:
  output:
    handlers: app/handlers/
    schemas:  app/schemas/
    tests:    tests/
  auto_approve: false             # always show diff before merging
  create_branch: true
  branch_prefix: autocraft/

validation:
  run_mypy: true
  run_ruff: true
  run_tests: true
  min_coverage: 80
  max_retries: 3
```

---

## CLI Reference

| Command | Description |
|---|---|
| `autocraft init` | Scaffold `autocraft.yaml` in the current directory |
| `autocraft generate "<description>"` | Run the full generation pipeline |
| `autocraft review` | Inspect or approve the last generated diff |

---

## How It Works

```
Natural Language Description
        │
        ▼
┌───────────────────┐
│  Intent Parser    │  Mistral extracts: method, path, handler_name,
│  (LLM Phase 1)   │  inputs+types, business rules, side-effects, auth
└────────┬──────────┘
         │
         ▼
┌───────────────────┐
│  Context Analyzer │  AST scans project → detects Pydantic models,
│  (AST)           │  ORM entities, function signatures, decorators
└────────┬──────────┘
         │
         ▼
┌───────────────────┐
│  Code Generator   │  Senior-grade mega-prompt → Mistral produces
│  (LLM Phase 2)   │  handler + schemas + tests as a JSON bundle
└────────┬──────────┘
         │
         ▼
┌───────────────────┐
│  Validation       │  ast.parse (hard gate) → mypy → ruff advisory
│  Pipeline        │
└────────┬──────────┘
         │
         ▼
┌───────────────────┐
│  Review Gateway   │  ruff --fix auto-repair → write to disk
│  (Git-Native)    │  → git branch + stage → diff summary
└───────────────────┘
```

---

## Alternative LLM Providers

Edit `autocraft.yaml` and set the corresponding environment variable:

```yaml
# OpenAI GPT-4o
llm:
  provider: openai
  model: gpt-4o
# OPENAI_API_KEY=...

# Anthropic Claude
llm:
  provider: anthropic
  model: claude-sonnet-4-6
# ANTHROPIC_API_KEY=...
```

AutoCraft uses [litellm](https://github.com/BerriAI/litellm) under the hood,
so any provider supported by litellm works out of the box.

---

## Security

- **The LLM never receives credentials, `.env` files, or production data.**
- Generated code is validated in an isolated `tempfile.TemporaryDirectory` before being written to disk.
- `auto_approve: false` (default) — every generation requires a human diff review.
- The `.env` file is in `.gitignore` and never committed.

---

## Contributing

Pull requests are welcome. For major changes, open an issue first.

```bash
git clone https://github.com/autocraft-ai/autocraft
cd autocraft
pip install -e ".[dev]"
pytest
```

---

## License

[MIT](LICENSE) © 2026 AutoCraft Contributors
