# Workflow — Production-Grade AI Code Review Agent

## 1. 1. Fetch and scope the diff

Pull the PR diff and changed files via fetch_diff, drop generated/vendored/lockfile paths, and split into hunks within the configured file/line budget.

## 2. 2. Assemble minimal context

For each hunk, use repo_context and search_codebase to gather surrounding code and referenced symbol definitions — only what is needed to judge the change.

## 3. 3. Run static analysis & secret scan

Execute run_static_analysis and secret_scan over the changed files and pass their structured results to the model as corroborating evidence.

## 4. 4. Review security-first

The model reviews in priority order (security, correctness, concurrency, performance, API, tests), applies the severity rubric, and writes grounded file:line comments with fixes.

## 5. 5. Apply the escalation gate

policy_check flags protected areas; any match (or a detected secret) forces escalate=true and caps the verdict, regardless of the model's view.

## 6. 6. Publish the review

post_review posts inline comments, a summary and verdict, sets the status check, and labels the PR. Re-runs update existing comments instead of duplicating.

## 7. 7. Learn from outcomes

Record which findings humans accepted vs. dismissed; use false-positive and dismissal rates to tune prompts, severity thresholds, and the ignore list.
