policy

package
v0.0.0-...-b8e9622 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package policy loads project-specific category + ModificationGuidance rules from a YAML file and applies them to chunks during build/reindex.

The yaml format is intentionally small: a list of categories, each with a name, a set of path globs, and three guidance fields (also_review, required_tests, watch_out). First-match-by-glob wins; unmatched chunks keep an empty Category and nil Guidance.

Glob support: '*' matches a single path segment; '**' matches zero or more segments. Matching is left-anchored to the chunk's File field as already stored — keep paths repo-relative (e.g. "core/state/**").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GuidanceFromJSON

func GuidanceFromJSON(raw string) (*types.ModificationGuidance, error)

GuidanceFromJSON is the inverse of GuidanceJSON. Empty string returns nil (treat "no guidance" and "missing column" the same).

func GuidanceJSON

func GuidanceJSON(g *types.ModificationGuidance) (string, error)

GuidanceJSON is the round-trip helper used by the store to persist the Guidance struct as a TEXT column. Returns "" for nil so the column NULL-or-empty semantics stay consistent.

Types

type CategoryRule

type CategoryRule struct {
	Name          string   `yaml:"name" json:"name"`
	Paths         []string `yaml:"paths" json:"paths"`
	AlsoReview    []string `yaml:"also_review" json:"also_review"`
	RequiredTests []string `yaml:"required_tests" json:"required_tests"`
	WatchOut      []string `yaml:"watch_out" json:"watch_out"`
}

CategoryRule is one classification entry. A chunk's File is tested against each path glob; the first hit determines the category.

type Policy

type Policy struct {
	Version    int            `yaml:"version" json:"version"`
	Categories []CategoryRule `yaml:"categories" json:"categories"`
}

Policy is the loaded ruleset. Categories are evaluated in order.

func Load

func Load(path string) (*Policy, error)

Load parses a policy yaml from disk. Empty path returns an empty policy (matches nothing) so callers can treat "no policy file" the same as "policy with no rules".

func Parse

func Parse(raw []byte) (*Policy, error)

Parse decodes the yaml bytes into a Policy. Returned errors include the path-level context the caller provided (file path or "inline").

func (*Policy) Apply

func (p *Policy) Apply(chunks []types.Chunk) map[string]int

Apply annotates each chunk with Category + Guidance based on the first matching CategoryRule. Mutates chunks in place. Idempotent: re-applying the same policy is a no-op for chunks that already match the same rule.

Returns counts per category (including "" for unmatched) so callers can print a coverage summary.

func (*Policy) Validate

func (p *Policy) Validate() error

Validate checks for obvious authoring mistakes — duplicate category names, missing required fields. Glob syntax is not pre-validated because filepath.Match is lenient; bad globs simply never match.

Jump to

Keyboard shortcuts

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