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 ¶
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 ¶
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 ¶
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.