Metadata-Version: 2.4
Name: codeguardian-offline
Version: 0.1.0
Summary: Offline AI QA Assistant
Author-email: CodeGuardian Maintainers <maintainers@example.com>
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: typer>=0.12.0
Requires-Dist: rich>=13.0.0
Requires-Dist: sqlmodel>=0.0.16
Requires-Dist: httpx>=0.27.0
Provides-Extra: ui
Requires-Dist: playwright>=1.42.0; extra == "ui"
Provides-Extra: ai
Requires-Dist: ollama<1.0,>=0.2.0; extra == "ai"
Requires-Dist: chromadb<0.6.0,>=0.4.24; extra == "ai"
Requires-Dist: sentence-transformers>=2.5.1; extra == "ai"
Provides-Extra: scan
Requires-Dist: tree-sitter>=0.21.0; extra == "scan"
Requires-Dist: tree-sitter-python>=0.21.0; extra == "scan"
Requires-Dist: tree-sitter-javascript>=0.21.0; extra == "scan"
Requires-Dist: tree-sitter-java>=0.21.0; extra == "scan"
Provides-Extra: server
Requires-Dist: fastapi>=0.110.0; extra == "server"
Requires-Dist: uvicorn>=0.29.0; extra == "server"
Provides-Extra: full
Requires-Dist: codeguardian[ai,scan,server,ui]; extra == "full"
Provides-Extra: dev
Requires-Dist: codeguardian[full]; extra == "dev"
Requires-Dist: pytest>=8.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
Requires-Dist: ruff>=0.4.0; extra == "dev"

# CodeGuardian

An **Offline AI QA Assistant** that tests applications automatically and explains failures.

No internet. No API keys. No cloud services.

## Architecture & Features

- **CLI Automation**: Built with `Typer` and `Rich` for a premium terminal experience.
- **API Testing**: Uses `HTTPX` to validate JSON endpoints.
- **UI Testing**: Uses `Playwright` for headless browser automation and UI validation.
- **Static Analysis**: Hooks into `Semgrep` and `Ruff`.
- **RAG & Knowledge Base**: Parses source code with `Tree-sitter`, embeds it using `SentenceTransformers`, and stores it in `ChromaDB`.
- **Local AI Explanations**: Queries your local `Ollama` (`qwen2.5-coder` recommended) to explain test failures by correlating test errors with the relevant source code.

## Installation

Ensure you have Python 3.10+ installed.

CodeGuardian uses optional dependencies so you only install what you need.

```bash
git clone <repository>
cd CodeGuardian
python -m venv venv

# On Windows:
.\venv\Scripts\activate
# On Mac/Linux:
source venv/bin/activate
```

Install CodeGuardian with the features you need:

| Use case | Command | Approx size |
|---|---|---|
| API testing only | `pip install -e .` | ~50MB |
| + UI testing | `pip install -e .[ui]` | ~200MB |
| + AI explanations | `pip install -e .[ai]` | ~3GB |
| + Code scanning | `pip install -e .[scan]` | ~100MB |
| Everything | `pip install -e .[full]` | ~3.5GB |

*(Note: AI explanations require PyTorch which is ~2GB. Playwright requires an extra step: `playwright install chromium`).*

### Install Ollama

Install [Ollama](https://ollama.com/) on your local machine if you plan to use AI features. CodeGuardian will automatically pull the recommended model (`qwen2.5-coder`) when you first use the `ask` command.

## Usage

### 1. Initialize
Initialize the CodeGuardian database and pre-compile any language grammars:
```bash
cd /path/to/your/project
codeguardian init
```

### 2. Configure Tests
Create a `codeguardian-api.json` or `codeguardian-ui.json` in your project root. 
CodeGuardian will validate your config using Pydantic before running.

**codeguardian-api.json**
```json
{
  "base_url": "https://httpbin.org",
  "tests": [
    {"name": "Get Request", "url": "/get", "method": "GET", "expected_status": 200},
    {"name": "Not Found", "url": "/status/404", "method": "GET", "expected_status": 404}
  ]
}
```

**codeguardian-ui.json**
```json
{
  "browser": "chromium",
  "headless": true,
  "tests": [
    {
      "name": "Check Example Domain",
      "steps": [
        {"action": "navigate", "url": "http://example.com"},
        {"action": "assert_visible", "selector": "h1"}
      ]
    }
  ]
}
```

### 3. Run Tests
Run both API and UI tests (results will be logged to SQLite):
```bash
codeguardian test
# Or target specific suites:
# codeguardian test --api-only
# codeguardian test --ui-only
```

### 4. Build Knowledge Base
Scan the project to run static analysis and build the ChromaDB vector index:
```bash
codeguardian scan .
```

### 5. Ask the AI
If tests fail, query the AI. CodeGuardian will fetch the latest failures, pull relevant source code from ChromaDB, and ask Ollama to explain what went wrong:
```bash
codeguardian ask "Why did the API tests fail?"
```

### 6. Generate Reports
Export beautiful HTML reports or JUnit XML for CI/CD integrations:
```bash
codeguardian report --format html
codeguardian report --format junit
codeguardian report --format both
```
