In this note
  1. 01System Goals
  2. 02Architecture
  3. 03Repository Loading
  4. 04Project Indexing
  5. 05Static Analysis Layer
  6. 06Verification Execution
  7. 07Risk Scoring
  8. 08Review Output
  9. 09GitHub Integration
  10. 10Engineering Principles

Reviewing a GitHub repository is an engineering investigation. Before making any judgment, a reviewer needs to understand the project boundary, runtime model, dependency graph, testing surface, and the paths where bugs would actually hurt users.

A review agent should be built around that process: a code-aware system that clones or inspects a repository, builds a project map, runs local verification, and ties every finding to a file, a command, and a failure mode. A generic chatbot commenting on isolated snippets does not get you there.

System Goals

The agent has three goals:

  • Build a structured understanding of the repository.
  • Detect high-signal engineering risks.
  • Produce findings a maintainer can act on immediately.

Correctness, security, maintainability, and test gaps come before style preferences. A good agent should be able to say: this request path accepts user input, passes it into this parser, writes to this storage layer, and currently has no test covering malformed input.

Architecture

The review agent is a pipeline:

GitHub Repository
      |
      v
Repository Loader
      |
      v
Project Indexer
      |
      v
Static Analysis + Semantic Search
      |
      v
Test / Build / Lint Executor
      |
      v
Risk Scoring Engine
      |
      v
Review Report Generator

Each stage owns one responsibility. Keeping them separate makes the agent easier to debug, measure, and improve.

Repository Loading

The first step is to load the repository in a reproducible way. The agent needs to capture:

  • GitHub URL, branch, commit SHA, and pull request number if available.
  • Language and framework signals from files like package.json, pyproject.toml, go.mod, Cargo.toml, pom.xml, or build.gradle.
  • CI configuration from .github/workflows, circleci, buildkite, or similar directories.
  • Dependency lockfiles such as package-lock.json, pnpm-lock.yaml, yarn.lock, poetry.lock, uv.lock, or Cargo.lock.

The commit SHA matters because the review has to be reproducible. If a finding points at a moving branch instead of a commit, the evidence can drift.

Project Indexing

Once the repository is available locally, the agent builds a project index with both structural and semantic data:

  • File tree, with generated artifacts and build output excluded.
  • Entry points: API routes, CLI commands, app bootstraps, workers, scheduled jobs.
  • Exported functions, classes, interfaces, and modules.
  • Dependency edges between files.
  • Test files mapped to implementation files.
  • Configuration files and environment variable usage.

For small repositories, filesystem traversal and language-aware parsers may be enough. Larger codebases need a hybrid index:

  • Fast lexical search with tools like ripgrep.
  • AST parsing where a parser exists for the language.
  • Embedding-based retrieval for semantic questions.
  • Call graph or import graph extraction for dependency reasoning.

The agent does not need to read every file into the model context. It can retrieve files based on the current review hypothesis.

Static Analysis Layer

The static analysis layer looks for patterns that deserve human attention. Examples:

  • User input reaching filesystem, SQL, shell, network, or deserialization APIs.
  • Authentication or authorization checks that are missing or inconsistent.
  • Broad catch blocks that hide operational failures.
  • Unsafe shell command construction.
  • Missing request size limits.
  • Update flows prone to races.
  • Shared mutable state in concurrent code.
  • Unbounded retries, pagination, recursion, or queue processing.
  • Secrets accidentally committed into source.
  • Error paths without tests.

This layer should combine deterministic rules with LLM reasoning. Rules handle exact patterns; an LLM can connect several files into one behavioral path.

Verification Execution

A review agent becomes much more useful when it can run the commands a maintainer would run:

npm test
npm run lint
npm run typecheck
pytest
go test ./...
cargo test

The agent should infer commands from package scripts, CI workflows, and README instructions. For each run it should record the command, exit code, runtime, the failure output that matters, and whether the failure looks related to the reviewed change.

A finding that was never run is weaker evidence. Commands that fail for missing services or credentials still belong in the report.

Risk Scoring

Not every issue deserves the same attention. A practical agent scores findings by risk:

risk = impact * likelihood * reachability * confidence
  • Impact measures how bad the failure would be.
  • Likelihood measures how likely the failure is in normal usage.
  • Reachability measures whether the code path is exposed to real users or automation.
  • Confidence measures how much evidence the agent has.

Scoring keeps the review from turning into a long list of low-value comments. The list should start with issues that could cause data loss, security exposure, production outages, broken releases, or major regressions.

Review Output

A useful finding is short, specific, and tied to evidence:

Severity: High
File: src/api/import.ts
Issue: Uploaded files are parsed before size and content-type validation.
Why it matters: Large or malformed files can cause excessive memory usage before rejection.
Suggested fix: Validate request size and MIME type before reading the full body.
Verification: Add tests for oversized files, unsupported MIME types, and malformed payloads.
Evidence: The import route calls parseUpload(body) before validateUploadMetadata(req).

Vague advice like "improve validation" gives a maintainer nothing to check. The format above names the failure mode instead.

GitHub Integration

Two integration modes are common:

  • Pull request review mode: the agent reviews the diff, then expands into surrounding files when needed.
  • Repository audit mode: the agent reviews the whole repository and produces an architecture and risk report.

For pull requests, scope control matters. The agent should focus on changed behavior, regression risk, and missing tests. For full repository audits, it can go wider: architecture risks, dependency concerns, dead code, documentation gaps.

A GitHub-native implementation can use GitHub App authentication, pull_request webhooks, Checks API status reporting, review comments for line-specific findings, artifacts for full reports, and labels for severity or review state.

The agent should not block merges automatically unless the organization explicitly configures that behavior. Early versions are safer as advisory reviewers.

Engineering Principles

The main design principle is evidence-first review. The agent reads, searches, runs, and verifies before it makes a claim.

  • Prefer repository conventions over generic conventions.
  • Keep generated fixes small and easy to review.
  • Separate observation from inference.
  • Cite files and commands for every important claim.
  • Degrade gracefully when tests or dependencies cannot run.
  • Avoid overwhelming maintainers with low-confidence findings.

Human review stays in charge. The agent's job is to make it faster, more systematic, and more precise.