codereview

package
v0.0.33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

README

This somewhat sprawling tool handles code-oriented cleanups.

It is often easier to find and fix code issues than attempt to prompt engineer them to never occur, particularly for mechanically detectable issues and issues around particular APIs, etc.

The tool gets run whenever a git commit occurs.

There are three different types of code reviews that this tool does.

(This is not well reflected in the code organization yet.)

Mechanical

The simplest are high confidence code issues that can be cleaned up reliably and mechanically, such as running gofmt.

Detection of these is based on the current state of the repository and which files have changed in the last commit.

When we detect such an issue we fix it on disk and ask the agent to amend the most recent commit to incorporate our changes. (We ask the agent to amend rather than silently doing it ourselves so that it is aware that the changes have occurred.)

Differential

These are code issues that are characterized by having a regression relative to the initial state of the code, such as having tests that are newly failing. (If a test was failing coming in, we should not require the agent to fix it; this could generate unwanted changes and work.)

Detection of these is based on the diff between the initial commit of the repository and the current commit.

When we detect such an issue we inform the agent about it. Some of them could be fixed more or less mechanically but because we are not necessarily confident about it it is better to tell the agent about the possible issue and ask the agent do the work.

Within this category we have both "Info" and "Error" messages, based again on our confidence.

LLM reviewer

These are code issues that are not detectable mechanically but might be detectable by an LLM reviewer.

We use a large system prompt with guidance on what sorts of issues to look for and how to respond to them. (It is not a general purpose "look for issues", although we should perhaps add one of those as well.) It may also contain extra guidance to help the LLM effectively use its advice, e.g. for recent language/stdlib additions.

This detector is currently marked as experimental.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeReviewer

type CodeReviewer struct {
	// contains filtered or unexported fields
}

A CodeReviewer manages quality checks.

func NewCodeReviewer

func NewCodeReviewer(ctx context.Context, repoRoot, sketchBaseRef string) (*CodeReviewer, error)

func (*CodeReviewer) CurrentCommit

func (r *CodeReviewer) CurrentCommit(ctx context.Context) (string, error)

CurrentCommit retrieves the current git commit hash

func (*CodeReviewer) HasReviewed

func (r *CodeReviewer) HasReviewed(commit string) bool

func (*CodeReviewer) IsInitialCommit

func (r *CodeReviewer) IsInitialCommit(commit string) bool

func (*CodeReviewer) ModTidy

func (r *CodeReviewer) ModTidy(ctx context.Context) ([]string, error)

ModTidy runs go mod tidy if go module files have changed. Returns a list of files changed by go mod tidy (empty if none).

func (*CodeReviewer) RequireNoUncommittedChanges

func (r *CodeReviewer) RequireNoUncommittedChanges(ctx context.Context) error

func (*CodeReviewer) RequireNormalGitState

func (r *CodeReviewer) RequireNormalGitState(_ context.Context) error

RequireNormalGitState checks that the git repo state is pretty normal.

func (*CodeReviewer) ResolveCommit

func (r *CodeReviewer) ResolveCommit(ctx context.Context, ref string) (string, error)

func (*CodeReviewer) Run

func (*CodeReviewer) RunMechanicalChecks

func (r *CodeReviewer) RunMechanicalChecks(ctx context.Context) string

RunMechanicalChecks runs all mechanical checks and returns a message describing any changes made.

func (*CodeReviewer) Tool

func (r *CodeReviewer) Tool() *llm.Tool

Tool returns a tool spec for a CodeReview tool backed by r.

func (*CodeReviewer) WarmTestCache

func (r *CodeReviewer) WarmTestCache(modifiedFile string)

WarmTestCache runs 'go test -c' on relevant packages in the background to warm up the Go build cache. This is intended to be called after patch operations to prepare for future differential testing. It uses the base commit (before state) to warm cache for packages that will likely be tested during code review.

type GoplsIssue

type GoplsIssue struct {
	Position string // File position in format "file:line:col-range"
	Message  string // Description of the issue
}

GoplsIssue represents a single issue reported by gopls check

type RelatedFile

type RelatedFile struct {
	Path        string  // Path to the file
	Correlation float64 // Correlation score (0.0-1.0)
}

RelatedFile represents a file historically related to the changed files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL