review

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package review defines the Reviewer abstraction: what a review needs, what it produces, and how findings are modelled. Backends (the claude CLI today, SDKs later) live in subpackages.

Index

Constants

View Source
const AttributionFooter = "" /* 130-byte string literal not displayed */

AttributionFooter is appended to published comments when publish.attribution is enabled.

View Source
const OutputSchema = `` /* 1406-byte string literal not displayed */

OutputSchema is passed to the backend (claude --json-schema) so findings arrive as validated structured output.

View Source
const SystemPrompt = `` /* 1439-byte string literal not displayed */

SystemPrompt is appended to the backend's system prompt: the reviewer persona and the line-reporting contract the position resolver depends on.

Variables

View Source
var AllCategories = []Category{"bug", "security", "performance", "docs", "style", "design"}

Categories the reviewer knows how to look for.

Functions

func BuildUserPrompt

func BuildUserPrompt(req Request) string

BuildUserPrompt renders the review request: MR metadata, category scope, custom instructions, then the bounded diff with annotated line numbers.

func ChunkDiffs

func ChunkDiffs(diffs []gitlabx.FileDiff, exclude []string, maxKB int) (chunks [][]gitlabx.FileDiff, skipped []string)

ChunkDiffs filters the diffs sent to the model and splits them into review passes: excluded and generated files are dropped entirely, and the rest is packed (in original order) into chunks of at most maxKB each so oversized MRs become several passes instead of a truncated one. Files individually larger than the whole budget are skipped.

Types

type Category

type Category string

Category of a finding.

func (Category) Valid

func (c Category) Valid() bool

Valid reports whether c is a known category.

type Event

type Event struct {
	Kind EventKind
	Text string
}

Event is one progress update for the TUI's review log.

type EventKind

type EventKind int

EventKind classifies progress events streamed during a review.

const (
	EventInit EventKind = iota
	EventStatus
	EventToolUse
	EventText
	EventRetry
)

type Finding

type Finding struct {
	ID         string
	File       string // new path, repo-relative
	OldFile    string // as reported by the model for renames; advisory only
	Line       LineRef
	Severity   Severity
	Category   Category
	Title      string
	Body       string // markdown, user-editable
	Suggestion string // optional replacement for the flagged line
	State      FindingState
}

Finding is one suggested review comment.

func (Finding) RenderBody

func (f Finding) RenderBody(attribution bool) string

RenderBody formats a finding as the GitLab comment body. Suggestions become GitLab suggestion blocks only when anchored to a new-side line (GitLab applies suggestions to the commented line).

func (Finding) RenderFallbackBody

func (f Finding) RenderFallbackBody(attribution bool, blobURL string) string

RenderFallbackBody formats a finding for a general MR note when no inline position could be resolved; blobURL may be empty.

type FindingState

type FindingState int

FindingState tracks a finding through the curation flow.

const (
	StatePending FindingState = iota
	StateAccepted
	StateRejected
	StatePublished
	StateFellBack // published, but as a general note because no position resolved
)

func (FindingState) String

func (s FindingState) String() string

type LineRef

type LineRef struct {
	OldLine *int
	NewLine *int
}

LineRef locates a finding in a diff: new-side line for added/context lines, old-side line for removed lines. Nil means not applicable.

type Request

type Request struct {
	// RepoPath is the checkout the review runs in (the subprocess cwd).
	RepoPath string
	// MR carries metadata shown to the model (title, description, branches).
	MR gitlabx.MRDetail
	// Diffs is the bounded, pre-filtered set of file diffs to review.
	Diffs []gitlabx.FileDiff
	// Truncated lists files that were excluded or cut by the diff budget.
	Truncated []string
	// Instructions is extra prompt text: global then per-project.
	Instructions string
	// Categories to report on.
	Categories []Category

	Model        string
	Timeout      time.Duration
	MaxBudgetUSD float64
}

Request is everything a backend needs to run one review.

type Result

type Result struct {
	Summary   string
	Findings  []Finding
	Warnings  []string // dropped findings, truncation notes
	SessionID string
	CostUSD   float64
	Raw       []byte // raw output for drift debugging; persisted by the caller
}

Result is a completed review.

func MergeResults

func MergeResults(parts []*Result) *Result

MergeResults combines the results of a multi-pass review into one, with finding IDs reassigned to stay unique.

func ParseResult

func ParseResult(data []byte) (*Result, error)

ParseResult decodes and validates a backend's structured output. Findings that fail validation are dropped into Warnings rather than failing the review; a completely undecodable payload is an error.

type Reviewer

type Reviewer interface {
	Name() string
	// CheckAvailable verifies the backend can run (binary present, version
	// supported) and returns a user-actionable error otherwise.
	CheckAvailable(ctx context.Context) error
	Review(ctx context.Context, req Request, onEvent func(Event)) (*Result, error)
}

Reviewer runs reviews. Implementations must be safe to reuse serially; onEvent is called from the reviewing goroutine.

type Severity

type Severity string

Severity of a finding, weakest to strongest.

const (
	SeverityInfo     Severity = "info"
	SeverityMinor    Severity = "minor"
	SeverityMajor    Severity = "major"
	SeverityCritical Severity = "critical"
)

func (Severity) AtLeast

func (s Severity) AtLeast(min Severity) bool

AtLeast reports whether s is min or stronger.

func (Severity) Valid

func (s Severity) Valid() bool

Valid reports whether s is a known severity.

Directories

Path Synopsis
Package claudecli runs reviews by shelling out to the Claude Code CLI in headless mode (claude -p, stream-json output, structured output schema).
Package claudecli runs reviews by shelling out to the Claude Code CLI in headless mode (claude -p, stream-json output, structured output schema).

Jump to

Keyboard shortcuts

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