Documentation
¶
Overview ¶
Package autotype decides whether a commit warrants a design review, using cheap heuristics first and an optional classifier for ambiguous cases.
Index ¶
- Variables
- func AllMatch(patterns []string, paths []string) (bool, error)
- func AnyMatch(patterns []string, path string) (bool, error)
- func CountChangedLines(diff string) int
- func MatchMessage(patterns []string, msg string) (string, error)
- type Classifier
- type Decision
- type ErrOnClassifier
- type Heuristics
- type Input
- type Method
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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:
- TRIGGER — any trigger_paths hit, diff size large, file count large, or trigger_message_patterns match → Run=true.
- SKIP — diff below MinDiffLines, all files match skip_paths, or skip_message_patterns match → Run=false.
- 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.
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.