review

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package review provides AI-powered code review for git diffs. It parses structured feedback from a provider and returns categorized issues, quality scores, and actionable suggestions. It also provides ReviewDiff for lightweight post-task annotation reviews.

Index

Constants

View Source
const (
	VerdictPass = "PASS"
	VerdictFail = "FAIL"
)

Verdict values for post-task reviews.

View Source
const (
	SeverityCritical   = "critical"   // bugs, security holes, data loss
	SeverityMajor      = "major"      // logic errors, missing error handling
	SeverityMinor      = "minor"      // style, naming, duplication
	SeveritySuggestion = "suggestion" // optional improvements
)

Severity levels for code review issues.

View Source
const Author = "ai-reviewer"

Author is the annotation author used for AI code review annotations.

Variables

This section is empty.

Functions

func ExtractVerdict

func ExtractVerdict(text string) string

ExtractVerdict scans review text for "VERDICT: PASS" or "VERDICT: FAIL". Defaults to VerdictPass when no verdict line is found.

func FormatMarkdown

func FormatMarkdown(r *Review, diff, source string) string

FormatMarkdown renders a Review as a Markdown document.

func GetDiff

func GetDiff(workDir string) (string, error)

GetDiff runs `git diff HEAD~1` in workDir and returns the diff output. Returns an empty string (no error) when there is no parent commit or no diff.

func ReviewDiff

func ReviewDiff(ctx context.Context, p provider.Provider, model string, timeout time.Duration, diff, taskTitle string) (string, error)

ReviewDiff calls the provider with a structured code review prompt for the given diff and task title. It returns the full review text (markdown) and an error. The text ends with a "VERDICT: PASS" or "VERDICT: FAIL" line. If the diff is empty the function returns a short note without calling the provider.

Types

type Issue

type Issue struct {
	// Severity is one of: critical, major, minor, suggestion.
	Severity string `json:"severity"`

	// File is the path of the affected file (may be empty for cross-cutting issues).
	File string `json:"file"`

	// Line is the approximate line number (0 means unknown).
	Line int `json:"line"`

	// Title is a short one-line description of the issue.
	Title string `json:"title"`

	// Detail explains the problem in full.
	Detail string `json:"detail"`

	// Fix is a concrete suggestion or code snippet to resolve the issue.
	Fix string `json:"fix"`
}

Issue is a single code review finding.

type Review

type Review struct {
	// Score is an overall code quality score from 1–10.
	Score float64 `json:"score"`

	// Summary is a 2–3 sentence high-level assessment.
	Summary string `json:"summary"`

	// Issues is the list of findings ordered by severity (critical first).
	Issues []Issue `json:"issues"`

	// Praise lists specific things that are well done.
	Praise []string `json:"praise"`

	// Suggestions lists general improvement ideas that don't map to a single issue.
	Suggestions []string `json:"suggestions"`

	// TestFeedback is targeted feedback on test coverage and quality.
	TestFeedback string `json:"test_feedback"`

	// SecurityNotes lists any security-relevant observations.
	SecurityNotes []string `json:"security_notes"`
}

Review is the structured output of an AI code review.

func Perform

func Perform(ctx context.Context, prov provider.Provider, model string, timeout time.Duration, diff, taskContext, goal string) (*Review, error)

Perform sends the provided diff to the AI provider and returns a structured review. taskContext is optional — if set it's included in the prompt so the AI can judge whether the code actually solves the intended PM task.

func (*Review) Counts

func (r *Review) Counts() (critical, major, minor, suggestion int)

Counts returns the number of issues at each severity level.

Jump to

Keyboard shortcuts

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