codereview

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CategorizeChanges added in v0.21.5

func CategorizeChanges(diff string) string

CategorizeChanges gives a rough per-category count of changed lines.

func DetectProjectType added in v0.21.5

func DetectProjectType(root string) string

DetectProjectType names the project type from marker files in root.

func ExtractFileContextForChanges added in v0.21.5

func ExtractFileContextForChanges(workspaceRoot, diff string) string

ExtractFileContextForChanges returns up to the first 500 lines of each changed file (skipping files excluded by ShouldSkipFileForContext and paths escaping workspaceRoot), formatted as markdown code blocks. "" when no readable files remain.

func ExtractHunkContext added in v0.21.5

func ExtractHunkContext(root, diff string) string

ExtractHunkContext excerpts the current content of each changed file around its hunks, with line numbers, so a reviewer can judge a change against its surroundings. Skipped: generated/vendored/binary files and anything outside root.

func ExtractKeyComments added in v0.21.5

func ExtractKeyComments(diff string) string

ExtractKeyComments lists added comments that explain intent (see IsImportantComment), capped so they can't crowd out the diff.

func ExtractKeyCommentsFromDiff added in v0.21.5

func ExtractKeyCommentsFromDiff(diff string) string

ExtractKeyCommentsFromDiff scans added diff lines for comments ("//" or "#") judged important by IsImportantComment and returns up to 10 of them, each prefixed with the file it appeared in. "" when none are found.

func IsImportantComment added in v0.18.7

func IsImportantComment(comment string) bool

IsImportantComment reports whether a review comment contains a keyword that marks it as important enough to highlight. Long // comments are treated as important regardless of content.

func IsValidRepoFilePath added in v0.21.5

func IsValidRepoFilePath(workspaceRoot, relPath string) bool

IsValidRepoFilePath reports whether relPath is a safe in-repo path: no ".." traversal and the cleaned absolute path stays inside workspaceRoot. An absolute relPath is checked as-is (not re-anchored under workspaceRoot), so "/etc/passwd" against any workspace root is rejected.

func RangeDiff added in v0.21.10

func RangeDiff(ctx context.Context, dir, base string) (string, error)

RangeDiff returns the changes HEAD introduces since its merge-base with base (`git diff base...HEAD`) — what a pull request against base would show.

func ShouldSkipFileForContext added in v0.21.5

func ShouldSkipFileForContext(filePath string) bool

ShouldSkipFileForContext reports whether relPath should be excluded from review context extraction: lockfiles, minified bundles, generated code, coverage artifacts, binaries/images, and vendored or git-internal paths.

func SplitContextLines added in v0.21.5

func SplitContextLines(content string) ([]string, bool)

SplitContextLines splits file content into lines for excerpting, rejecting content too large to be worth excerpting.

Types

type CodeReviewResult

type CodeReviewResult = types.CodeReviewResult

CodeReviewResult represents the result of a code review

type CodeReviewService

type CodeReviewService struct {
	// contains filtered or unexported fields
}

CodeReviewService provides a unified interface for code review operations

func NewCodeReviewService

func NewCodeReviewService(cfg *configuration.Config, logger *utils.Logger) *CodeReviewService

NewCodeReviewService creates a new code review service instance

func (*CodeReviewService) GetDefaultAgentClient

func (s *CodeReviewService) GetDefaultAgentClient() api.ClientInterface

GetDefaultAgentClient returns the default agent client for this service

func (*CodeReviewService) PerformAgenticReview

func (s *CodeReviewService) PerformAgenticReview(ctx *ReviewContext, opts *ReviewOptions) (*types.CodeReviewResult, error)

PerformAgenticReview performs a stricter evidence-focused single-call review that requires structured output.

func (*CodeReviewService) PerformReview

func (s *CodeReviewService) PerformReview(ctx *ReviewContext, opts *ReviewOptions) (*types.CodeReviewResult, error)

PerformReview performs a single-call review of the staged change in ctx.

type FileExcerpt added in v0.21.5

type FileExcerpt struct {
	Path string
	Body string // markdown: "### path" heading plus fenced, line-numbered code
}

FileExcerpt is a formatted, line-numbered excerpt of one file.

func HunkExcerpts added in v0.21.5

func HunkExcerpts(root, diff string) []FileExcerpt

HunkExcerpts is ExtractHunkContext split per file, in diff order, so callers can apply their own size budget.

func HunkExcerptsFrom added in v0.21.5

func HunkExcerptsFrom(diff string, read func(rel string) ([]string, bool)) []FileExcerpt

HunkExcerptsFrom is HunkExcerpts with the post-image content supplied by read — e.g. from the git index, so a staged review isn't shown unstaged edits. Files that should never be excerpted are skipped before read.

func NewFileExcerpt added in v0.21.5

func NewFileExcerpt(root, rel string) (FileExcerpt, bool)

NewFileExcerpt returns the head of a file that has no diff hunks (e.g. an untracked new file), line-numbered and capped like hunk excerpts.

type ReviewContext

type ReviewContext struct {
	Diff            string // The code diff to review
	Config          *configuration.Config
	Logger          *utils.Logger
	FullFileContext string              // Code around each changed hunk
	AgentClient     api.ClientInterface // Agent API client for LLM calls
	// GoCtx is the cancellation context for LLM calls (SP-073). When set,
	// it replaces context.Background() so Stop/Ctrl+C can abort reviews.
	GoCtx context.Context
	// Metadata for enhanced context
	ProjectType      string // Project type (Go, Node.js, etc.)
	CommitMessage    string // Commit message/intent
	KeyComments      string // Key code comments explaining WHY
	ChangeCategories string // Categorization of changes
}

ReviewContext represents the context for a code review request

type ReviewOptions

type ReviewOptions struct {
	Type       ReviewType
	SkipPrompt bool
}

ReviewOptions contains options for the code review

type ReviewType

type ReviewType int

ReviewType defines the type of code review being performed

const (
	StagedReview ReviewType = iota // Used for reviewing Git staged changes
)

type StagedContext added in v0.21.5

type StagedContext struct {
	ProjectType      string
	CommitMessage    string
	KeyComments      string
	ChangeCategories string
	FullFileContext  string
}

StagedContext is the metadata attached to a staged-change review to help the model judge intent: what kind of project, what changed, and the code around each hunk.

func BuildRangeContext added in v0.21.10

func BuildRangeContext(ctx context.Context, dir, base, diff string) StagedContext

BuildRangeContext is BuildStagedContext for committed work: file context is read from HEAD, and the commit subjects since base stand in for the message.

func BuildStagedContext added in v0.21.5

func BuildStagedContext(ctx context.Context, dir, stagedDiff string) StagedContext

BuildStagedContext derives review metadata for stagedDiff. Paths in the diff are relative to the git top level, so files are resolved against the repository containing dir rather than the process working directory.

func (StagedContext) Apply added in v0.21.5

func (c StagedContext) Apply(rc *ReviewContext)

Apply copies the context into rc.

Jump to

Keyboard shortcuts

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