Metadata-Version: 2.5
Name: logicguard
Version: 0.1.0
Summary: Diff-aware static + LLM reasoning engine for business-logic flaws
Project-URL: Homepage, https://logicguard.me
Project-URL: Repository, https://github.com/Aviation3006/logicguard
Project-URL: Issues, https://github.com/Aviation3006/logicguard/issues
Author-email: Avi Narain <founder@logicguard.me>
License-Expression: MIT
License-File: LICENSE
Keywords: ast,business-logic,code-review,devsecops,llm,sarif,sast,security,static-analysis,tree-sitter
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2.0
Requires-Dist: rich>=13.7
Requires-Dist: tree-sitter-javascript>=0.23
Requires-Dist: tree-sitter-python>=0.23
Requires-Dist: tree-sitter-typescript>=0.23
Requires-Dist: tree-sitter>=0.24
Requires-Dist: typer>=0.12
Description-Content-Type: text/markdown

# LogicGuard

[![CI](https://github.com/Aviation3006/logicguard/actions/workflows/ci.yml/badge.svg)](https://github.com/Aviation3006/logicguard/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/logicguard.svg)](https://pypi.org/project/logicguard/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

LogicGuard is an open-source, diff-aware static + LLM reasoning engine that catches business-logic flaws and AI-generated code bugs that regex linters miss.

[Website](https://logicguard.me) · [Contributing](CONTRIBUTING.md)

## Quickstart

Run LogicGuard directly with [`uvx`](https://docs.astral.sh/uv/guides/tools/) or install it globally with `pipx`:

```bash
# Run without installing (zero-network AST pre-filter mode)
uvx logicguard diff --offline-only

# Or install globally with pipx
pipx install logicguard
logicguard scan src/
```

Scan a git diff using local Ollama (`qwen2.5-coder:7b` by default) or a cloud provider:

```bash
# Local Ollama (100% offline, default provider)
uvx logicguard diff --base main

# OpenRouter (e.g. free or custom models)
OPENROUTER_API_KEY=... uvx logicguard diff --provider openrouter --model openrouter/free

# Anthropic Claude
ANTHROPIC_API_KEY=... uvx logicguard scan src/ --provider anthropic
```

## GitHub Action

Drop LogicGuard into any pull request workflow to scan changed functions and upload SARIF 2.1.0 alerts directly to GitHub Code Scanning:

```yaml
name: LogicGuard Security Scan

on:
  pull_request:

permissions:
  contents: read
  security-events: write

jobs:
  logicguard:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Run LogicGuard diff scan
        uses: Aviation3006/logicguard@v0.1.0
        with:
          provider: openrouter
          model: openrouter/free
          api-key: ${{ secrets.OPENROUTER_API_KEY }}
          fail-on: high
```

Set `offline-only: "true"` if you want deterministic AST-only scanning with no API key, or pass `provider: anthropic` with your `ANTHROPIC_API_KEY`.

## Built-in Rules

LogicGuard ships with five AST + LLM rules supporting Python, JavaScript, TypeScript, and TSX (`logicguard rules`):

| Rule ID | Title | Default Severity | CWE | Languages |
| :--- | :--- | :--- | :--- | :--- |
| `auth_bypass` | Missing or Removed Authentication/Authorization Guard | `CRITICAL` | CWE-862 | Python, JS, TS, TSX |
| `ai_hallucinated_guard` | Hallucinated, Inverted, or No-Op Security Guard | `HIGH` | CWE-863 | Python, JS, TS, TSX |
| `idor_ownership` | Insecure Direct Object Reference (Missing Ownership/Tenant Check) | `HIGH` | CWE-639 | Python, JS, TS, TSX |
| `race_toctou` | Time-of-Check to Time-of-Use (TOCTOU) Race Condition | `HIGH` | CWE-367 | Python, JS, TS, TSX |
| `silent_except` | Silent Exception Swallowing Around State Changes | `HIGH` | CWE-390 | Python, JS, TS, TSX |

## Example CLI Finding

```text
+---------------------------------- app/routes/admin.py:1-6 -----------------------------------+
| [CRITICAL] auth_bypass - Missing or Removed Authentication/Authorization Guard               |
| Location: app/routes/admin.py:1-6 | Confidence: 0.96 | CWE-862                               |
| > 1 @app.post("/api/admin/users/{user_id}/promote")                                          |
| > 2 def promote_user(user_id: int, db: Session = Depends(get_db)):                           |
| > 3     user = db.get(User, user_id)                                                         |
| > 4     user.role = "admin"                                                                  |
| > 5     db.commit()                                                                          |
| > 6     return {"status": "promoted"}                                                        |
| Explanation: State-mutating admin endpoint promotes a user role without any authentication   |
| or admin role check dependency.                                                              |
| Remediation: Require an authenticated admin user via Depends(require_admin) and verify       |
| permissions before updating user.role.                                                       |
+----------------------------------------------------------------------------------------------+
                   Scan Summary                   
+------------------------------------------------+
| Findings             | 1                       |
| Files scanned        | 3                       |
| Candidates evaluated | 2                       |
| Provider             | ollama:qwen2.5-coder:7b |
| Duration             | 412.8 ms                |
+------------------------------------------------+
```

## Contributing & Links

Adding a new security rule takes just two files (`src/logicguard/rules/<rule_id>.py` and `tests/rules/test_<rule_id>.py`) with automatic discovery and zero central registry edits — see [CONTRIBUTING.md](CONTRIBUTING.md).

- Project homepage: [https://logicguard.me](https://logicguard.me)
- Contribution guide: [CONTRIBUTING.md](CONTRIBUTING.md)
- License: [MIT](LICENSE)
