Documentation
¶
Overview ¶
Package review implements the multi-concern LLM review pipeline.
Index ¶
- Constants
- func BuildPrompt(concern Concern, files []diff.File, contextLines int) string
- func BuildPromptEnhanced(concern Concern, files []diff.File, contextLines int) string
- func BuildReflectPrompt(findings []Finding, diffContext string) string
- func ChunkFiles(files []diff.File, concern Concern, contextLines int, maxPromptTokens int) [][]diff.File
- func EstimateTokens(s string) int
- func LookupCWEName(id string) string
- func MatchCWE(message, fix string) string
- func SystemPrompt(concern Concern) string
- type CWEMapping
- type Concern
- type Finding
- type ReflectResult
- type Severity
Constants ¶
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 ¶
BuildPrompt constructs the user prompt from a concern and parsed diff files.
func BuildPromptEnhanced ¶
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 ¶
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 ¶
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 ¶
LookupCWEName returns the human-readable name for a CWE ID.
func MatchCWE ¶
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 ¶
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 ¶
Concern defines a review focus area with its specialized prompt.
func AllConcerns ¶
func AllConcerns() []Concern
AllConcerns returns every available concern definition.
func BuildConcerns ¶
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 ¶
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.