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
- Variables
- func BuildUserPrompt(req Request) string
- func ChunkDiffs(diffs []gitlabx.FileDiff, exclude []string, maxKB int) (chunks [][]gitlabx.FileDiff, skipped []string)
- func ParseBodyTemplate(s string) (*template.Template, error)
- type Category
- type Event
- type EventKind
- type Finding
- type FindingState
- type LineRef
- type Request
- type Result
- type Reviewer
- type Severity
Constants ¶
AttributionFooter is appended to published comments when publish.attribution is enabled.
const DefaultBodyTemplate = "**[{{.severity}} · {{.category}}] {{.title}}**\n\n{{.body}}"
DefaultBodyTemplate is the built-in comment layout (publish.template). Fields available to templates: severity, category, title, body, file.
const OutputSchema = `` /* 1406-byte string literal not displayed */
OutputSchema is passed to the backend (claude --json-schema) so findings arrive as validated structured output.
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 ¶
var AllCategories = []Category{"bug", "security", "performance", "docs", "style", "design"}
Categories the reviewer knows how to look for.
Functions ¶
func BuildUserPrompt ¶
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 Finding ¶
type Finding struct {
ID string `json:"id"`
File string `json:"file,omitempty"` // new path, repo-relative; empty on MR-level manual comments
OldFile string `json:"old_file,omitempty"` // as reported by the model for renames; advisory only
Line LineRef `json:"line,omitzero"`
Severity Severity `json:"severity,omitempty"`
Category Category `json:"category,omitempty"`
Title string `json:"title,omitempty"`
Body string `json:"body"` // markdown, user-editable
Suggestion string `json:"suggestion,omitempty"` // optional replacement for the flagged line
State FindingState `json:"state"`
// Manual marks a comment written by the reviewer in the TUI rather than
// produced by the model: it publishes verbatim, without the body
// template or the attribution footer.
Manual bool `json:"manual,omitempty"`
}
Finding is one suggested review comment. The json tags define the stored form used by review/resultstore.
func (Finding) RenderBody ¶
RenderBody formats a finding as the GitLab comment body using tmpl (nil means the built-in layout). Suggestions become GitLab suggestion blocks only when anchored to a new-side line (GitLab applies suggestions to the commented line).
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) MarshalText ¶ added in v1.10.0
func (s FindingState) MarshalText() ([]byte, error)
MarshalText encodes the state as its display word, so persisted findings stay readable and survive reordering of the constants.
func (FindingState) String ¶
func (s FindingState) String() string
func (*FindingState) UnmarshalText ¶ added in v1.10.0
func (s *FindingState) UnmarshalText(text []byte) error
UnmarshalText is the inverse of MarshalText.
type LineRef ¶
type LineRef struct {
OldLine *int `json:"old_line,omitempty"`
NewLine *int `json:"new_line,omitempty"`
}
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
// Commits are the MR's commits, shown to the model as context (and for
// commit-message hygiene checks driven via Instructions).
Commits []gitlabx.Commit
// Template is the project's default MR description template, shown to the
// model so instructions can drive a description-vs-template hygiene
// check. Empty when the project has no template.
Template string
// 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 ¶
MergeResults combines the results of a multi-pass review into one, with finding IDs reassigned to stay unique.
func ParseResult ¶
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.
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). |
|
Package publisher posts curated findings back to a merge request — as live inline discussions, as a draft review published in one action, or as general notes when no diff position resolves — so every frontend (TUI, web GUI) publishes identically.
|
Package publisher posts curated findings back to a merge request — as live inline discussions, as a draft review published in one action, or as general notes when no diff position resolves — so every frontend (TUI, web GUI) publishes identically. |
|
Package resultstore persists completed review results — the summary and every finding with its curation state — so a review survives navigating away or closing the session, and can be reopened later.
|
Package resultstore persists completed review results — the summary and every finding with its curation state — so a review survives navigating away or closing the session, and can be reopened later. |
|
Package runlog persists the progress log of each review run — the same timestamped lines streamed to the review screen — so a run can be read back after its screen is gone.
|
Package runlog persists the progress log of each review run — the same timestamped lines streamed to the review screen — so a run can be read back after its screen is gone. |
|
Package runner orchestrates one review run end to end — checkout, prompt assembly, reviewer passes, result merging, and persistence — so every frontend (TUI, web GUI) drives the same pipeline and stores the same artifacts.
|
Package runner orchestrates one review run end to end — checkout, prompt assembly, reviewer passes, result merging, and persistence — so every frontend (TUI, web GUI) drives the same pipeline and stores the same artifacts. |