review

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package review implements the multi-concern LLM review pipeline.

Index

Constants

View Source
const ReflectSystemPrompt = `` /* 1296-byte string literal not displayed */

ReflectSystemPrompt is the system prompt for the self-reflection pass.

Variables

This section is empty.

Functions

func BuildPrompt

func BuildPrompt(concern Concern, files []diff.File, contextLines int) string

BuildPrompt constructs the user prompt from a concern and parsed diff files.

func BuildPromptEnhanced

func BuildPromptEnhanced(concern Concern, files []diff.File, contextLines int) string

BuildPromptEnhanced constructs a PR-Agent style prompt that separates new and old hunks with clear section markers. This helps the LLM distinguish added code from removed code more accurately.

func BuildReflectPrompt

func BuildReflectPrompt(findings []Finding, diffContext string) string

BuildReflectPrompt constructs the prompt for self-reflection. Returns an empty string if the resulting prompt exceeds maxReflectPromptSize, indicating reflection should be skipped.

func ChunkFiles

func ChunkFiles(files []diff.File, concern Concern, contextLines int, maxPromptTokens int) [][]diff.File

ChunkFiles splits files into groups that fit within the token budget. Each group's combined prompt should not exceed maxPromptTokens.

func EstimateTokens

func EstimateTokens(s string) int

EstimateTokens provides a BPE-approximation token count for a string. It splits on whitespace and punctuation, then applies a multiplier: ~1.3 tokens per word for English prose, ~2.0 tokens per word for code. This is significantly more accurate than the naive len(s)/4 heuristic.

func LookupCWEName

func LookupCWEName(id string) string

LookupCWEName returns the human-readable name for a CWE ID.

func MatchCWE

func MatchCWE(message, fix string) string

MatchCWE checks a finding's message (and fix) against the CWE database and returns the CWE ID if a match is found. Returns empty string if no match. Uses word boundary checks to avoid false positives from substring matching.

func SystemPrompt

func SystemPrompt(concern Concern) string

SystemPrompt returns the system prompt for a given concern.

Types

type CWEMapping

type CWEMapping struct {
	ID       string   // e.g. "CWE-89"
	Name     string   // e.g. "SQL Injection"
	Keywords []string // lowercase keywords to match in finding messages
}

CWEMapping maps a security finding pattern to a CWE identifier.

type Concern

type Concern struct {
	Name   string
	Prompt string
}

Concern defines a review focus area with its specialized prompt.

func AllConcerns

func AllConcerns() []Concern

AllConcerns returns every available concern definition.

func BuildConcerns

func BuildConcerns(names []string) []Concern

BuildConcerns returns concern definitions filtered by the given names.

type Finding

type Finding struct {
	Concern   string
	Severity  Severity
	File      string
	Line      int
	EndLine   int
	Message   string
	Fix       string
	Reasoning string
	CWE       string
}

Finding is an internal finding produced by a concern review.

func ApplyReflection

func ApplyReflection(findings []Finding, reflections []ReflectResult) []Finding

ApplyReflection filters and adjusts findings based on reflection results.

func ApplyReflectionWithScore

func ApplyReflectionWithScore(findings []Finding, reflections []ReflectResult, minScore int) []Finding

ApplyReflectionWithScore filters and adjusts findings based on reflection results. Findings with a score below minScore are dropped. A minScore of 0 disables score-based filtering.

func ParseResponse

func ParseResponse(response string, concernName string) []Finding

ParseResponse extracts structured findings from the LLM response text. It handles common formatting quirks: markdown code blocks, leading text, etc. If strict JSON parsing fails, it applies lenient fixes and then falls back to regex extraction.

type ReflectResult

type ReflectResult struct {
	Index    int    `json:"index"`
	Action   string `json:"action"`
	Severity string `json:"severity"`
	Score    int    `json:"score"`
	Message  string `json:"message"`
	Reason   string `json:"reason"`
}

ReflectResult holds the LLM's validation of a finding.

func ParseReflectResponse

func ParseReflectResponse(response string) []ReflectResult

ParseReflectResponse parses the self-reflection LLM response.

type Severity

type Severity int

Severity mirrors the public type for internal use.

const (
	SeverityInfo Severity = iota
	SeverityLow
	SeverityMedium
	SeverityHigh
	SeverityCritical
)

Jump to

Keyboard shortcuts

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