# Context-Aware Smart Reviewer

The **Smart Reviewer** is a graph-augmented code review tool that analyzes the downstream impact of changes. Unlike traditional linters that look at single files, the Smart Reviewer uses the Clew dependency graph to identify potential regressions in files that import or call the changed code.

## Architecture

The reviewer operates in a 4-stage pipeline:

1.  **Diff Analysis**: Parses Git diffs to identify changed files and content.
2.  **Impact Analysis**: Queries the Neo4j graph for files that depend on the changed code (Imports, Calls).
3.  **Context Assembly**: Fetches the source code of impacted files, respecting token limits (32k).
4.  **LLM Reasoning**: Sends the Diff + Context to an LLM to assess risk (HIGH/MEDIUM/LOW/SAFE).

## Usage

The reviewer is integrated into the `clew` CLI.

### Analyze Staged Changes
```bash
clew review --staged
```

### Analyze a Pull Request
compares `HEAD` against `origin/main`.
```bash
clew review --pr
```

## Configuration

The reviewer requires the following environment variables:

| Variable | Description | Default |
| :--- | :--- | :--- |
| `CLEW_API_URL` | URL of the Clew Engine API | `http://localhost:8000/v1` |
| `OPENAI_API_KEY` | Key for LLM reasoning | `None` (Required) |
| `OPENAI_MODEL` | LLM Model to use | `gpt-4-turbo-preview` |

## Security

- **Path Traversal**: The context fetcher enforces that all file paths must resolve within the repository root.
- **API Key Validation**: Keys are checked for the `sk-` prefix before use.
- **Redirects**: The client follows HTTP redirects (e.g. 307) from the API.

## Implementation Details

- **Code Location**: `src/clew/review/`
- **Tests**: `tests/review/`
