autotype

package
v0.53.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package autotype decides whether a commit warrants a design review, using cheap heuristics first and an optional classifier for ambiguous cases.

Index

Constants

This section is empty.

Variables

View Source
var ErrNeedsClassifier = errors.New("autotype: classifier required")

ErrNeedsClassifier is returned by Classify when heuristics are inconclusive and the provided Classifier is ErrOnClassifier (used by callers that want to dispatch the classifier asynchronously rather than run it inline).

Functions

func AllMatch

func AllMatch(patterns []string, paths []string) (bool, error)

AllMatch reports whether every path in paths matches at least one pattern in patterns. Returns false for an empty path list (nothing to match). Returns an error if any pattern is malformed.

func AnyMatch

func AnyMatch(patterns []string, path string) (bool, error)

AnyMatch reports whether any of the given patterns matches path using doublestar (bash-globstar) semantics. Returns an error if a pattern is malformed.

func CountChangedLines

func CountChangedLines(diff string) int

CountChangedLines counts `+` and `-` lines in a unified diff, excluding the `+++` and `---` file marker lines. Useful as a cheap proxy for "diff size" when deciding whether a change is trivial or large.

func MatchMessage

func MatchMessage(patterns []string, msg string) (string, error)

MatchMessage returns the first matching substring from msg for the first pattern in patterns that matches. Returns "" (no error) when no pattern matches. Returns an error if a pattern is an invalid regex.

Only the subject line (first line) of msg is considered.

Types

type Classifier

type Classifier interface {
	Decide(ctx context.Context, in Input) (yes bool, reason string, err error)
}

Classifier returns a yes/no + reason for ambiguous cases. Implementations typically wrap a SchemaAgent call.

type Decision

type Decision struct {
	Run    bool
	Reason string
	Method Method
}

Decision is the final verdict for a single commit.

func Classify

func Classify(ctx context.Context, in Input, h Heuristics, cls Classifier) (Decision, error)

Classify runs the heuristics in fixed order (trigger rules first, then skip rules, then classifier fallback) and returns a Decision.

Precedence:

  1. TRIGGER — any trigger_paths hit, diff size large, file count large, or trigger_message_patterns match → Run=true.
  2. SKIP — diff below MinDiffLines, all files match skip_paths, or skip_message_patterns match → Run=false.
  3. CLASSIFIER — ambiguous → delegate to cls.Decide.

type ErrOnClassifier

type ErrOnClassifier struct{}

ErrOnClassifier is a Classifier implementation that always returns ErrNeedsClassifier. Use from code paths that want to see "heuristic-only" decisions without blocking on a live agent.

func (ErrOnClassifier) Decide

func (ErrOnClassifier) Decide(ctx context.Context, in Input) (bool, string, error)

Decide implements Classifier.

type Heuristics

type Heuristics struct {
	MinDiffLines   int
	LargeDiffLines int
	LargeFileCount int

	TriggerPaths []string
	SkipPaths    []string

	TriggerMessagePatterns []string
	SkipMessagePatterns    []string
}

Heuristics holds the thresholds and patterns consulted before falling back to the classifier.

func DefaultHeuristics

func DefaultHeuristics() Heuristics

DefaultHeuristics returns the baked-in defaults that ship when the user hasn't overridden anything in config.

func (Heuristics) Validate

func (h Heuristics) Validate() error

Validate compiles each regex and checks each glob. Returns an error with the offending pattern so misconfigurations surface loudly at load time.

type Input

type Input struct {
	RepoPath     string
	GitRef       string
	Diff         string
	Message      string
	ChangedFiles []string
}

Input is what the heuristics and classifier operate on.

type Method

type Method string

Method identifies which layer produced a Decision.

const (
	MethodHeuristic  Method = "heuristic"
	MethodClassifier Method = "classifier"
)

Jump to

Keyboard shortcuts

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