Metadata-Version: 2.4
Name: astrix-code
Version: 1.1.0
Summary: Local-First AST & Compiler-Backed Deterministic AI Code Infrastructure (Supported by NVIDIA Inception)
Author: Astrix AI Team
Author-email: Astrix AI Team <info@astrix.com.tr>
License: MIT
Keywords: compiler,ast,determinism,code-generation,roslyn,security,nvidia,triton,tensorrt,ai-infrastructure
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Compilers
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Security
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28.0
Requires-Dist: rich>=13.0.0
Provides-Extra: database
Requires-Dist: pyodbc>=5.0.0; extra == "database"
Provides-Extra: all
Requires-Dist: requests>=2.28.0; extra == "all"
Requires-Dist: rich>=13.0.0; extra == "all"
Requires-Dist: pyodbc>=5.0.0; extra == "all"
Dynamic: author
Dynamic: license-file
Dynamic: requires-python

# Astrix AI — Local-First Deterministic AI Infrastructure

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg)]()
[![Determinism](https://img.shields.io/badge/Determinism-100%25%20Verified-cyan.svg)]()
[![Docker](https://img.shields.io/badge/Docker-Ready-2496ED.svg)](https://www.docker.com/)
[![NVIDIA CUDA](https://img.shields.io/badge/NVIDIA%20CUDA-Supported-76B900.svg)](https://developer.nvidia.com/cuda-zone)
[![LSP Ready](https://img.shields.io/badge/LSP-Cursor%20%7C%20Windsurf%20%7C%20VSCode-purple.svg)]()

> **Astrix AI** is an LLM-Agnostic, Local-First Deterministic Code Verification and Compiler Infrastructure. It sits between Large Language Models (LLMs) and production codebases, guaranteeing **zero hallucinations**, native compiler verification, OWASP security guardrails, and isolated sandbox execution before code ever touches disk.

---

## 🏛️ Architecture Flow (Astrix Determinism Loop)

Astrix AI treats Foundation Models as untrusted probabilistic engines. Every token passes through a 4-layer deterministic compiler pipeline:

```
+-----------------------------------------------------------------------------------+
|               DEVELOPER INTERFACES: CLI / VS CODE / CURSOR LSP / DOCKER           |
+-----------------------------------------------------------------------------------+
                                          |
                                          v
+-----------------------------------------------------------------------------------+
| LAYER 1: LLM GENERATOR (LLM-Agnostic Engine)                                      |
| - Connectors: Ollama (Local CUDA), OpenAI, Anthropic Claude, DeepSeek, vLLM, Groq |
| - Strict JSON Protocol: { "file_name", "language", "code" }                       |
+-----------------------------------------------------------------------------------+
                                          |
                                          v
+-----------------------------------------------------------------------------------+
| LAYER 2: IN-MEMORY AST COMPILER & SECURITY SENTRY                                 |
| - Roslyn C# AST Scope Engine (CS0103, CS0246, CS1002, CS1513 validation)          |
| - Python AST Engine (`ast.parse`, NameError, undefined variable resolution)       |
| - TypeScript / SWC Strict AST Validator                                           |
| - MS SQL Query Schema Lock (`sys.sp_describe_first_result_set`)                   |
| - Security & Secret Sentry: OWASP rules, API key leak detection, injection checks |
+-----------------------------------------------------------------------------------+
                                          |
                                 [Compilation & Security Check]
                                    /                     \
                             [Success]                  [Failure]
                                /                            \
                               v                              v
+-----------------------------------------------+   +-------------------------------+
| LAYER 3: DYNAMIC SANDBOX RUNNER               |   | LAYER 4: SELF-CORRECTION LOOP |
| - Isolated timed execution (3s timeout limit) |   | - Error is NEVER shown to dev |
| - Runtime zero-division & memory checks       |   | - Compiler diagnostics fed    |
| - Auto-Test Synthesizer (`--with-tests`)      |   |   back to LLM automatically   |
+-----------------------------------------------+   | - Max Retries Loop (1-5)      |
                               |                    +-------------------------------+
                      [Sandbox Passed]                                |
                               |                                      v
                               v                        [Dataset Collector Logs Pair]
+-----------------------------------------------+       [For Fine-Tuning LoRA/SFT]
| PRODUCTION-READY CLEAN CODE DELIVERED (0 ERR) |
+-----------------------------------------------+
```

---

## ⚡ Key Features

1. **Zero Hallucination Guarantee:** Generated code is never accepted until it passes native AST syntax parsing and compiler verification loops with 0 errors.
2. **Security & Secret Sentry:** Scans all code for accidental API key leaks (OpenAI, Claude, GitHub, AWS, JWT) and blocks dangerous vectors (`eval()`, `exec()`, `pickle.loads()`, `os.system()`, SQL Injection).
3. **Dynamic Sandbox Runner:** Executes code in an isolated subprocess with strict timeouts to verify runtime stability (no infinite loops or unhandled exceptions).
4. **Auto-Test Synthesizer:** Automatically writes and executes unit tests for synthesized code, delivering 100% verified code + test suites.
5. **Universal Language Server Protocol (LSP):** Connects with Cursor, Windsurf, VS Code, Zed, and Neovim to provide real-time inline compiler diagnostics.
6. **Fine-Tuning Dataset Exporter:** Logs every `[Broken Code -> Compiler Error -> Fixed Code]` iteration and exports directly to Alpaca, ShareGPT, or Hugging Face formats for model training.
7. **GitHub PR Reviewer Bot:** Automatically runs on Pull Requests, performs full compilation & security checks, and posts review summary tables.

---

## 🚀 Quickstart

### 1. Installation

From source:

```bash
git clone https://github.com/astrix-project/astrix-ai.git
cd astrix-ai
pip install -e .
```

### 2. Running CLI Commands

```bash
# 1. Verify codebase locally on CPU (0 server cost, zero data leak)
astrix check .

# 2. Synthesize code with local AI + Automated Unit Tests
astrix synthesize --prompt "Create an async JWT token verification service" -l python --with-tests

# 3. Export fine-tuning dataset collected from self-correction loops
astrix dataset stats
astrix dataset export --format alpaca --out ./finetune_dataset.json

# 4. Launch Language Server Protocol for Cursor / VS Code
astrix lsp

# 5. Install Git Pre-Commit Hook to block broken commits locally
astrix install-hooks
```

### 3. Docker Deployment

```bash
# Build and run with Docker
docker build -t astrix-ai .
docker run -p 8000:8000 astrix-ai

# Or using docker-compose
docker compose up -d
```

---

## ⚙️ Supported Model Providers (LLM-Agnostic)

Astrix AI works as an immutable deterministic compiler wrapper on top of **any foundation model**:

| Provider Flag | Backend | Description |
| :--- | :--- | :--- |
| `--provider ollama` | Local CUDA GPU | 100% Air-gapped, zero cloud cost (Qwen 2.5 Coder, Llama 3) |
| `--provider generic` | vLLM / DeepSeek / Groq | Any OpenAI-compatible endpoint with `--base-url` |
| `--provider openai` | GPT-4o / o1 | Official OpenAI API |
| `--provider anthropic` | Claude 3.5 Sonnet | Anthropic API integration |
| `--provider gemini` | Gemini 1.5 Pro / 2.0 Flash | Google AI Studio integration |
| `--provider mock` | Offline Test Mock | Offline testing & deterministic self-correction tests |

---

## 🧪 Running Test Suite

```bash
python -m unittest discover -s tests
```

---

## 🤝 Contributing

Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) and our [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for details on our code of conduct and the process for submitting pull requests.

---

## 📄 License

This project is licensed under the [MIT License](LICENSE).
