review

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package review provides daemon-free review orchestration: parallel batch execution, synthesis, and comment formatting.

Index

Constants

View Source
const (
	ResultDone   = "done"
	ResultFailed = "failed"
)

Result status values for ReviewResult.Status.

View Source
const MaxCommentLen = 60000

MaxCommentLen is the maximum length for a GitHub PR comment. GitHub's hard limit is ~65536; we leave headroom.

View Source
const QuotaErrorPrefix = "quota: "

QuotaErrorPrefix is prepended to error messages when a review fails due to agent quota exhaustion rather than a real error. Matches the prefix set by internal/daemon/worker.go.

View Source
const TimeoutErrorPrefix = "timeout: "

TimeoutErrorPrefix is prepended to error messages when a batch job is canceled because the batch exceeded its timeout and results were posted with the available reviews.

Variables

View Source
var ErrAllFailed = errors.New(
	"all review jobs failed")

ErrAllFailed is returned by Synthesize when every review job in the batch failed (excluding all-quota-skipped batches).

Functions

func BuildSynthesisPrompt

func BuildSynthesisPrompt(
	reviews []ReviewResult,
	minSeverity string,
) string

BuildSynthesisPrompt creates the prompt for the synthesis agent. When minSeverity is non-empty (and not "low"), a filtering instruction is appended.

func CountQuotaFailures

func CountQuotaFailures(reviews []ReviewResult) int

CountQuotaFailures returns the number of reviews that failed due to agent quota exhaustion rather than a real error.

func CountTimeoutCancellations added in v0.50.0

func CountTimeoutCancellations(reviews []ReviewResult) int

CountTimeoutCancellations returns the number of reviews that were canceled due to batch timeout.

func FormatAllFailedComment

func FormatAllFailedComment(
	reviews []ReviewResult,
	headSHA string,
) string

FormatAllFailedComment formats a comment when every job in a batch failed.

func FormatRawBatchComment

func FormatRawBatchComment(
	reviews []ReviewResult,
	headSHA string,
) string

FormatRawBatchComment formats all review outputs as expanded inline sections. Used as a fallback when synthesis fails.

func FormatSynthesizedComment

func FormatSynthesizedComment(
	output string,
	reviews []ReviewResult,
	headSHA string,
) string

FormatSynthesizedComment wraps synthesized output with header and metadata.

func IsQuotaFailure

func IsQuotaFailure(r ReviewResult) bool

IsQuotaFailure returns true if a review's error indicates a quota skip rather than a real failure.

func IsTimeoutCancellation added in v0.50.0

func IsTimeoutCancellation(r ReviewResult) bool

IsTimeoutCancellation returns true if a review was canceled because the batch timed out and posted early.

func SkippedAgentNote

func SkippedAgentNote(reviews []ReviewResult) string

SkippedAgentNote returns a markdown note listing agents that were skipped due to quota exhaustion. Returns "" if none.

func Synthesize

func Synthesize(
	ctx context.Context,
	results []ReviewResult,
	opts SynthesizeOpts,
) (string, error)

Synthesize combines multiple review results into a single formatted comment string.

Single successful result: returns it directly (no LLM call). All failed: returns failure comment. Multiple results with successes: runs synthesis agent, falls back to raw format on error.

func TrimPartialRune added in v0.40.0

func TrimPartialRune(s string) string

TrimPartialRune removes a trailing incomplete UTF-8 sequence that may result from slicing a string at an arbitrary byte offset. Only the last rune is inspected — pre-existing invalid bytes elsewhere in the string are left untouched.

Types

type BatchConfig

type BatchConfig struct {
	RepoPath     string
	GitRef       string   // "BASE..HEAD" range
	Agents       []string // agent names (resolved per-job)
	ReviewTypes  []string // resolved review types
	Reasoning    string
	ContextCount int
	// GlobalConfig enables workflow-aware agent/model resolution.
	// When set, each job resolves its agent and model through
	// config.ResolveAgentForWorkflow / ResolveModelForWorkflow,
	// matching the CI poller's behavior. When nil, agents are
	// used as-is (backward compatible).
	GlobalConfig *config.Config
	// AgentRegistry is an optional registry for dependency injection in testing.
	// If nil, the global agent registry is used.
	AgentRegistry map[string]agent.Agent
	// MinSeverity is the minimum severity threshold for the review prompt.
	// When non-empty (and not "low"), agents are instructed to filter findings.
	MinSeverity string
}

BatchConfig holds parameters for a parallel review batch.

type ReviewResult

type ReviewResult struct {
	Agent      string
	ReviewType string
	Output     string
	Status     string // ResultDone or ResultFailed
	Error      string
}

ReviewResult holds the outcome of a single review in a batch. Decoupled from storage.BatchReviewResult for daemon-free use.

func RunBatch

func RunBatch(
	ctx context.Context,
	cfg BatchConfig,
) []ReviewResult

RunBatch executes all review_type x agent combinations in parallel. Uses goroutines + sync.WaitGroup, no daemon/database.

type SynthesizeOpts

type SynthesizeOpts struct {
	// Agent name for synthesis (empty = first available).
	Agent string
	// Model override for the synthesis agent.
	Model string
	// MinSeverity filters findings below this level.
	MinSeverity string
	// RepoPath is the working directory for the synthesis agent.
	RepoPath string
	// GitRef is the reviewed git ref, passed to the synthesis agent.
	GitRef string
	// HeadSHA is used for comment formatting headers.
	HeadSHA string
	// GlobalConfig allows runtime agent resolution to honor ACP naming/command overrides.
	GlobalConfig *config.Config
}

SynthesizeOpts controls synthesis behavior.

Jump to

Keyboard shortcuts

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