Documentation
¶
Overview ¶
Package engine implements the rule checking engine for Guardian. It provides a registry of rule checkers, a unified orchestrator, and diff parsing utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Registry = map[string]RuleChecker{}
Registry maps rule type names to their corresponding checkers.
Functions ¶
func RegisterChecker ¶
func RegisterChecker(c RuleChecker)
RegisterChecker registers a RuleChecker in the global registry by its type name.
Types ¶
type CheckContext ¶
type CheckContext struct {
ChangedFiles []string
DiffContent string
RuleConfig map[string]interface{}
Severity string
RuleID string
RuleDesc string
}
CheckContext provides all the information a RuleChecker needs to evaluate a rule.
type DiffPatternForbiddenChecker ¶
type DiffPatternForbiddenChecker struct{}
DiffPatternForbiddenChecker checks that added lines in the diff do not match any of the configured forbidden regular expressions. Optionally scoped to specific file path patterns via only_in_paths.
func (*DiffPatternForbiddenChecker) Check ¶
func (c *DiffPatternForbiddenChecker) Check(ctx *CheckContext) ([]Violation, error)
Check evaluates the diff_pattern_forbidden rule against the given context.
func (*DiffPatternForbiddenChecker) Type ¶
func (c *DiffPatternForbiddenChecker) Type() string
Type returns the checker type identifier.
type DiffPatternRequiresChecker ¶
type DiffPatternRequiresChecker struct{}
DiffPatternRequiresChecker checks that when files matching only_in_paths are changed, at least one of the required_regexes patterns appears somewhere in the added lines of the diff. If none match, a violation is returned.
func (*DiffPatternRequiresChecker) Check ¶
func (c *DiffPatternRequiresChecker) Check(ctx *CheckContext) ([]Violation, error)
Check evaluates the diff_pattern_requires rule against the given context.
func (*DiffPatternRequiresChecker) Type ¶
func (c *DiffPatternRequiresChecker) Type() string
Type returns the checker type identifier.
type Engine ¶
Engine orchestrates rule checking by running all configured rules against the given diff and filtering out exceptions.
type EngineResult ¶
EngineResult holds the aggregated results of running all rules.
type FileDiff ¶
type FileDiff struct {
Path string
AddedLines []string // lines starting with "+" (without the leading "+")
}
FileDiff represents the diff for a single file.
type ImportsForbiddenChecker ¶
type ImportsForbiddenChecker struct{}
ImportsForbiddenChecker checks that files matching from_globs do not contain imports from paths matching forbid_globs. It works by inspecting added lines in the diff for path segments derived from the forbidden glob patterns.
func (*ImportsForbiddenChecker) Check ¶
func (c *ImportsForbiddenChecker) Check(ctx *CheckContext) ([]Violation, error)
Check evaluates the imports_forbidden rule against the given context.
func (*ImportsForbiddenChecker) Type ¶
func (c *ImportsForbiddenChecker) Type() string
Type returns the checker type identifier.
type MetaChecker ¶
type MetaChecker struct{}
MetaChecker detects unauthorized changes to governance files (.agreements/constitution.yml and .agreements/rules.yml). Changes to these files without a corresponding accepted proposal produce a violation.
type RuleChecker ¶
type RuleChecker interface {
// Check evaluates the rule against the given context and returns any violations found.
Check(ctx *CheckContext) ([]Violation, error)
// Type returns the unique identifier for this checker type (e.g., "imports_forbidden").
Type() string
}
RuleChecker is the interface that all rule type checkers must implement.
type Violation ¶
type Violation struct {
RuleID string `json:"rule_id"`
Severity string `json:"severity"`
Description string `json:"description"`
FilePath string `json:"file_path"`
DiffSnippet string `json:"diff_snippet"`
LLMExplanation string `json:"llm_explanation"`
}
Violation represents a single rule violation found during checking.