classify

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package classify groups changed files by their architectural role (handler, repository, model, test, …) so each file's AOI pre-scan can be narrowed to the dimensions that actually apply. A test file doesn't need a cryptography review; a handler does need an input-validation pass.

Shared by `prr audit` (whole-repo) and `prr review` (PR diffs) — both feed the result into security.ScanAreasOfInterestClassified.

Index

Constants

This section is empty.

Variables

AllFileTypes lists valid classification types for prompt construction.

Functions

func Classify

func Classify(
	ctx context.Context,
	client ai.Client,
	files []File,
	cachedTypes map[string]FileType,
	onProgress func(status string),
) (map[string]FileType, error)

Classify runs the LLM classifier on the given files using the cheap model. Returns a map of file path → FileType.

cachedTypes maps file paths to previously cached classifications. Files with cached results are skipped. Pass nil to classify everything.

Returns partial results plus errors.Join of any batch errors, so the caller can decide whether to fail or proceed with unknowns.

func DimensionsForType

func DimensionsForType(ft FileType) []string

DimensionsForType returns the dimension slugs to include in the AOI prompt for the given file type. Unknown types get all dimensions.

func SetMaxConcurrency

func SetMaxConcurrency(n int)

SetMaxConcurrency sets the max number of classification batches run in parallel. Values <= 0 reset to the default. Not safe to call concurrently with classification in flight; intended to be called once at startup.

Types

type File

type File struct {
	Path    string
	Content string
}

File is the classifier input: a path and (a snippet of) its content. Audit reads full file content from disk via CollectFiles; review reads the head-of-branch version of each diffed file. Either way only the first ~50 lines are sent to the model — enough for imports and top-level declarations.

type FileClassification

type FileClassification struct {
	File string   `json:"file"`
	Type FileType `json:"type"`
}

FileClassification holds a file path and its LLM-determined type.

type FileType

type FileType string

FileType is the architectural role of a source file.

const (
	FileTypeTest           FileType = "test"
	FileTypeHandler        FileType = "handler"
	FileTypeRepository     FileType = "repository"
	FileTypeSQL            FileType = "sql"
	FileTypeModel          FileType = "model"
	FileTypeClient         FileType = "client"
	FileTypeWorker         FileType = "worker"
	FileTypeBusinessLogic  FileType = "business-logic"
	FileTypeInfrastructure FileType = "infrastructure"
	FileTypeUnknown        FileType = "unknown"
)

Jump to

Keyboard shortcuts

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