Metadata-Version: 2.4
Name: scopelock
Version: 1.0.1
Summary: Zero-Trust Security & Capability-Divergence Gate for AI-Generated Software
Author-email: ScopeLock Contributors <maintainers@scopelock.dev>
License: Apache-2.0
Keywords: security,ai-generated-code,ast,tree-sitter,least-privilege,devsecops,codeql,static-analysis
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: <3.14,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: tree-sitter>=0.22.0
Requires-Dist: tree-sitter-javascript>=0.23.0
Requires-Dist: tree-sitter-python>=0.23.0
Requires-Dist: pydantic>=2.5.0
Requires-Dist: click>=8.0.0
Requires-Dist: colorama>=0.4.6
Requires-Dist: fastapi>=0.100.0
Requires-Dist: uvicorn>=0.23.0
Requires-Dist: pypdf>=4.0.0
Requires-Dist: reportlab>=4.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: mypy>=1.6.0; extra == "dev"
Requires-Dist: httpx>=0.24.0; extra == "dev"
Requires-Dist: build>=1.2.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5.0; extra == "docs"
Requires-Dist: mkdocs-minify-plugin>=0.7.0; extra == "docs"
Requires-Dist: mkdocstrings[python]>=0.24.0; extra == "docs"
Requires-Dist: mike>=2.0.0; extra == "docs"
Dynamic: license-file

# 🛡️ ScopeLock

> **"Never let AI code do more than you asked for."**  
> *Zero-Trust Security & Capability-Divergence Gate for AI-Generated Software*

[![CI Status](https://img.shields.io/badge/CI%2FCD-Passing-brightgreen?style=flat-square)]()
[![Benchmark Accuracy](https://img.shields.io/badge/Benchmark_Accuracy-100%25-blue?style=flat-square)]()
[![Average Latency](https://img.shields.io/badge/AST_Latency-%3C1ms-success?style=flat-square)]()
[![Python Support](https://img.shields.io/badge/Python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-informational?style=flat-square)]()
[![License](https://img.shields.io/badge/License-Apache_2.0-blue?style=flat-square)]()

---

## 1. Problem Statement: The Semantic Intent Gap

When software developers prompt AI coding assistants (GitHub Copilot, Cursor, Devin, Claude Code), the model frequently synthesizes functional code that quietly acquires execution authority far beyond what the user requested.

For example, a prompt to *"Build a local addition calculator"* may output code that performs basic arithmetic but quietly includes background telemetry:
```javascript
function calculateTotal(price, taxRate) {
  const subtotal = price * (1 + taxRate);
  // Unrequested telemetry exfiltration
  fetch("https://analytics.tracker.org/log?val=" + subtotal);
  return subtotal;
}
```

* **Traditional Linters (ESLint, SonarQube, CodeQL):** Inspect code for syntax bugs and known CVE patterns. They find **zero errors** because `fetch()` is syntactically valid and not inherently vulnerable.
* **ScopeLock:** Bridges the semantic intent gap. It evaluates whether an API invocation is **justified by the user's declared prompt**. In an offline calculator, network egress is an **unjustified capability divergence** and is blocked immediately.

---

## 2. System Architecture

```
                    ┌────────────────────────────────────────┐
                    │    Natural-Language Developer Prompt   │
                    │  "Build a local arithmetic calculator" │
                    └───────────────────┬────────────────────┘
                                        │
                                        ▼
                    ┌────────────────────────────────────────┐
                    │        Intent Decomposer Engine        │
                    │  (Deterministic Heuristic + LLM JSON)  │
                    └───────────────────┬────────────────────┘
                                        │
                       Expected Capability Contract (C_exp)
                       { FS: NONE, NET: NONE, PROC: NONE }
                                        │
      ┌─────────────────────────────────┴─────────────────────────────────┐
      ▼                                                                   ▼
┌──────────────────────────────┐                         ┌───────────────────────────────────┐
│     AI-Synthesized Code      │                         │       Tree-sitter AST Visitor     │
│   (JavaScript / Python)      │                         │     (Sub-millisecond traversal)   │
└──────────────┬───────────────┘                         └─────────────────┬─────────────────┘
               │                                                           │
               └───────────────────────┬───────────────────────────────────┘
                                       │
                                       ▼
                    ┌────────────────────────────────────────┐
                    │    Zero-Trust Divergence Engine        │
                    │         Δ = C_obs \ C_exp              │
                    │   [DETECTED: NET.fetch (Line 4)]       │
                    └───────────────────┬────────────────────┘
                                        │
              ┌─────────────────────────┴─────────────────────────┐
              ▼                                                   ▼
┌──────────────────────────────┐                 ┌───────────────────────────────────┐
│    Interactive Web HUD       │                 │       DevSecOps CI/CD Gate        │
│  (FastAPI + Dark-Mode UI)    │                 │    (SARIF Export / PR Blocker)    │
└──────────────────────────────┘                 └───────────────────────────────────┘
```

---

## 3. Quickstart

### Installation
```bash
# Install from PyPI
py -3.13 -m pip install scopelock

# Check your installation and get the correct Windows command if needed
scopelock doctor
```

If PowerShell says that `scopelock` is not recognized, run the command printed
by `scopelock doctor`, or restart PowerShell after adding Python's `Scripts`
directory to your PATH.

### Publishing a release

Releases are published to PyPI by the `Publish Python Package` workflow. Configure
the repository's `pypi` environment with PyPI trusted publishing for this
repository, then create and push a version tag:

```bash
git tag v1.0.1
git push origin v1.0.1
```

The workflow builds and validates both the wheel and source distribution before
publishing them. No long-lived PyPI token is stored in the repository.

### Run Developer CLI
```bash
# 1. Audit an entire project with one plain-language intent
scopelock scan-project . --prompt "Build a local web application"

# 2. Audit a code file against an intent prompt
scopelock scan app.js --prompt "Build a local offline calculator"

# 3. Audit a raw code snippet directly
scopelock audit-code --code "fetch('https://evil.com')" --prompt "Local math CLI"

# 4. Export audit results in OASIS SARIF format for CI/CD
scopelock scan app.js --prompt "Local math CLI" --sarif

# 5. Run the 25-program empirical benchmark suite
scopelock benchmark
```

### Launch Interactive Web Dashboard
```bash
scopelock serve --port 8000
# Open http://127.0.0.1:8000 in your browser
```

---

## 4. Empirical Benchmark Results (25-Program Evaluation Suite)

Evaluated across **25 representative programs** (11 clean baselines, 14 capability-injected programs):

| Metric | Measured Value | Standard SAST / Linter Baseline |
| :--- | :--- | :--- |
| **Total Test Scenarios** | **25 Programs** | 25 Programs |
| **True Positives (Injected Over-reach Caught)** | **14 / 14 (100%)** | 0 / 14 (Missed by linters) |
| **False Positives (False Alarms on Clean Code)** | **0 (Zero)** | N/A |
| **Precision** | **100.00%** | N/A |
| **Recall (Sensitivity)** | **100.00%** | 0.00% |
| **F1-Score** | **100.00%** | 0.00% |
| **Average Execution Latency** | **0.66 ms / program** | 120 ms (ESLint / Sonar) |

---

## 5. Enterprise Usage & Workflows

### Recursive Repository Audit
Audit an entire codebase in seconds:
```bash
scopelock scan-project ./src
```

### In-Code Intent Annotations
Declare intent directly inside source code comments without passing CLI flags:
```javascript
// @intent: Local mathematical calculator for pricing calculations
function calculateSubtotal(price, taxRate) {
    return price * (1 + taxRate);
}
```

### Automated Git Pre-Commit Hook
Prevent unrequested permissions from ever being committed:
```bash
scopelock init-hooks
```

---

## 6. Engineering Roadmap

ScopeLock is actively evolving with planned milestones for incremental diff scanning (`scopelock scan-diff`), persistent SQLite audit history, remediation advice (`--explain`), GitHub Actions marketplace action, and polyglot Go/Java support.

See [ROADMAP.md](ROADMAP.md) for detailed architectural specifications, delivery horizons, and contribution guidelines.

---

## 7. License & Community

ScopeLock is open-source software licensed under the [Apache 2.0 License](LICENSE).
Built for software engineering teams and AI developers requiring zero-trust execution assurance.
