Help us shape the future of Go! Take the 2026 Go Developer Survey

rules

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package rules loads declarative lint rules and maps typed Jev answers to deterministic decisions. Repository-provided rule files are untrusted data.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDecision = errors.New("invalid rule decision")
View Source
var ErrInvalidPack = errors.New("invalid rule pack")
View Source
var ErrInvalidRule = errors.New("invalid rule")
View Source
var ErrInvalidSelector = errors.New("invalid rule path selector")
View Source
var ErrPackLimit = errors.New("rule pack limit exceeded")
View Source
var ErrUnsupportedSchema = errors.New("unsupported rule pack schema")

Functions

func Questions

func Questions(ctx context.Context, selections []Selection) ([]contextplan.Binding, error)

Questions copies typed criteria into planner bindings. It returns no partial result for duplicate or invalid selections.

func ValidateSelectors added in v0.4.0

func ValidateSelectors(includes, excludes []string) error

ValidateSelectors checks the same safe glob subset used by rule selection.

Types

type Decision

type Decision struct {
	RuleID     string
	WorkItemID string
	Path       string
	Side       git.Side
	StartLine  int
	EndLine    int
	Severity   Severity
	Title      string
	Message    string
	Kind       string
	Value      float64
	Confidence *float64
}

Decision carries fixed rule metadata, immutable Git coordinates, and one validated numeric signal. Value is a probability for Noul/Choice and a normalized score for Score; Kind names that distinction.

func Decide

func Decide(ctx context.Context, batch contextplan.Batch, selections []Selection, response jev.Response) ([]Decision, error)

Decide validates the complete provider response before emitting any decision. selections may include other batches; only exact question IDs in batch apply.

type Mandate added in v0.4.0

type Mandate struct {
	ID   string
	Body string
}

Mandate is one freeform Markdown requirement. ID is its path relative to a rule root.

func ReadMandates added in v0.4.0

func ReadMandates(ctx context.Context, root string) ([]Mandate, error)

ReadMandates returns bounded, validated Markdown files in stable path order.

type Pack

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

func CompileMandates added in v0.4.0

func CompileMandates(mandates []Mandate) (Pack, error)

CompileMandates applies the same fixed policy to built-in and loaded Markdown.

func Load

func Load(reader io.Reader) (Pack, error)

Load parses and validates one untrusted declarative rule pack.

func LoadContext

func LoadContext(ctx context.Context, reader io.Reader) (Pack, error)

LoadContext adds cancellation to bounded rule loading for CI callers.

func LoadDirectory added in v0.4.0

func LoadDirectory(ctx context.Context, root string) (Pack, error)

LoadDirectory reads Markdown mandates under root without following symlinks. Invalid or over-limit input returns no partial pack.

func WithOverrides added in v0.4.0

func WithOverrides(pack Pack, threshold *float64, severity *Severity) (Pack, error)

WithOverrides applies only explicitly provided run values, preserving rule metadata otherwise.

func WithPolicy added in v0.4.0

func WithPolicy(pack Pack, threshold float64, severity Severity) (Pack, error)

WithPolicy applies one trusted run policy to every mandate in a pack.

func (Pack) Rules

func (p Pack) Rules() []Rule

Rules returns independent copies; changing them cannot alter a loaded pack.

type Rule

type Rule struct {
	ID             string
	Type           string
	Instructions   string
	Body           string
	NoulCriteria   *jev.NoulCriteria
	ChoiceCriteria map[string]string
	ScoreCriteria  []string
	TriggerChoices []string
	Threshold      float64
	Severity       Severity
	Title          string
	Message        string
	Paths          []string
	Sides          []git.Side
}

type Selection

type Selection struct {
	GroupID    string
	Item       git.WorkItem
	Rule       Rule
	QuestionID string
}

Selection binds one validated rule to one immutable Git work item.

func Select

func Select(ctx context.Context, pack Pack, groups []contextplan.Group) ([]Selection, error)

Select applies declarative path/side selectors in canonical item/rule order.

func SelectWithPaths added in v0.4.0

func SelectWithPaths(ctx context.Context, pack Pack, groups []contextplan.Group, includes, excludes []string) ([]Selection, error)

SelectWithPaths applies run-level source-path filters before rule selection. A matching exclude takes precedence over every include.

type Severity

type Severity string
const (
	Low      Severity = "low"
	Medium   Severity = "medium"
	High     Severity = "high"
	Critical Severity = "critical"
)

Jump to

Keyboard shortcuts

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