Documentation
¶
Overview ¶
Package review hosts the model-agnostic finding validator and the runtime Finding type used by the TUI.
Validation enforces docs/review-finding-schema.md against the parsed diff produced by internal/diff. Rejected findings are quarantined with a reason rather than guessed at, per the v1 schema contract.
Index ¶
- Constants
- func Validate(candidates []FindingCandidate, modelName string, idx *diff.Index) ([]Finding, []Quarantined)
- type Finding
- type FindingCandidate
- type FindingState
- type Host
- type IssueContext
- type LinkedIssueFetcher
- type ModelReviewResult
- type Quarantined
- type ReviewInput
- type ReviewTarget
- type Severity
Constants ¶
const ( MaxDescriptionBytes = 8 * 1024 MaxIssueBodyBytes = 8 * 1024 MaxLinkedIssues = 10 )
Budget caps on the context contribution to a reviewer prompt. The description and each linked-issue body count toward an adapter's input budget (DefaultInputBudgetBytes, 1 MiB); bounding them here guarantees enrichment can never be the reason a review busts the budget and fails.
Variables ¶
This section is empty.
Functions ¶
func Validate ¶
func Validate(candidates []FindingCandidate, modelName string, idx *diff.Index) ([]Finding, []Quarantined)
Validate converts model candidates into validated Findings, enforcing every rule in docs/review-finding-schema.md:106-118.
Each candidate is evaluated independently; both the accepted Findings and the Quarantined slice are returned so the TUI can show debug-only rejected items without dropping them on the floor.
Types ¶
type Finding ¶
type Finding struct {
File string
Line int
Severity Severity
Title string
Evidence string
SuggestedComment string
FixHint string
Confidence float64
Model string
State FindingState
}
Finding is a validated review candidate ready for the TUI. Model and State are runtime metadata not present in the model's raw output.
type FindingCandidate ¶
type FindingCandidate struct {
File string `json:"file"`
Line int `json:"line"`
Severity string `json:"severity"`
Title string `json:"title"`
Evidence string `json:"evidence"`
SuggestedComment string `json:"suggested_comment"`
FixHint string `json:"fix_hint"`
Confidence float64 `json:"confidence"`
}
FindingCandidate is the transport-layer shape of a finding returned by a model CLI. Severity is kept as a string here; Validate converts it to a typed Severity.
Field ordering and JSON tags mirror docs/review-finding-schema.md exactly so the same struct can be used for both encoding the schema example in the prompt and decoding the model's reply.
type FindingState ¶
type FindingState int
FindingState is the TUI workflow state for a finding. Initial state on every fresh validation is StatePending; the TUI mutates state in M4.
const ( StatePending FindingState = iota StateApproved StateDismissed )
type IssueContext ¶ added in v0.2.0
IssueContext is one same-host issue a PR/MR closes. Body may be "" when the issue exists but its body could not be fetched.
type LinkedIssueFetcher ¶ added in v0.2.0
type LinkedIssueFetcher interface {
FetchLinkedIssues(ctx context.Context, target ReviewTarget) (issues []IssueContext, notes []string, err error)
}
LinkedIssueFetcher is implemented by providers that can resolve the same-host issues a PR/MR formally closes. It is an OPTIONAL capability: the app type-asserts a provider to it and skips acceptance-criteria enrichment when the assertion fails.
Return contract:
- issues: successfully resolved acceptance criteria (may be empty).
- notes: non-fatal, human-readable diagnostics (an issue was dropped, a count cap was hit) — surfaced in the run summary, never swallowed.
- err: TOTAL failure only (the closing-refs query itself failed); the caller surfaces it as one note and proceeds with no criteria.
type ModelReviewResult ¶
type ModelReviewResult struct {
Model string
Findings []FindingCandidate
RawOutput string
}
ModelReviewResult is what a model adapter returns after invocation. RawOutput preserves the model's stdout so the TUI's debug surface can show it when validation rejects everything.
type Quarantined ¶
type Quarantined struct {
Candidate FindingCandidate
Reason string
}
Quarantined holds a finding that failed validation, with the reason preserved so the TUI's debug surface can explain why.
type ReviewInput ¶
type ReviewInput struct {
Target ReviewTarget
Title string
Author string
Description string // PR/MR body, verbatim (may be ""); populated by Fetch
// AcceptanceCriteria holds the same-host issues this PR/MR formally
// closes, resolved via LinkedIssueFetcher. Empty is the normal "no
// linked issues" state, not an error.
AcceptanceCriteria []IssueContext
Files []*diff.DiffFile
RawDiff string
}
ReviewInput is the normalized input the review core consumes. Provider adapters produce this shape regardless of which CLI fetched the diff.
func (*ReviewInput) CapContext ¶ added in v0.2.0
func (in *ReviewInput) CapContext() []string
CapContext bounds Description and AcceptanceCriteria in place and returns a human-readable note for every truncation or drop it performed (nil when nothing was capped). Context is bounded, never silently shrunk: callers surface the notes so the operator knows the model saw less than the source.
type ReviewTarget ¶
type ReviewTarget struct {
Host Host
URL string
Owner string
Repo string
Number int
HeadRef string
HeadSHA string
BaseRef string
BaseSHA string
StartSHA string
}
ReviewTarget identifies the PR/MR being reviewed.
HeadSHA is the commit OID at the time the diff was fetched. It is the capture-time anchor used when posting review comments back upstream — re-resolving at post time would risk silently re-anchoring to a moved HEAD if the PR got pushed mid-review.
BaseSHA and StartSHA are the GitLab diff-refs required to post inline review threads (positioned at file:line in the diff view). GitHub uses HeadSHA alone; for GitLab we need all three. Empty for GitHub targets.
type Severity ¶
type Severity int
Severity enumerates the four severity buckets v1 supports.
func ParseSeverity ¶
ParseSeverity maps a model-output severity string to the typed enum. Unknown strings return an error so the validator quarantines the candidate rather than guessing.