Documentation
¶
Overview ¶
Package rules handles staghorn rule parsing, registry, and rendering.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertToClaude ¶
ConvertToClaude converts a staghorn rule to Claude Code rules format. It preserves the frontmatter (required for path-scoping) and adds a staghorn header.
Types ¶
type Frontmatter ¶
type Frontmatter struct {
Paths []string `yaml:"paths,omitempty"` // Glob patterns for path-scoping
}
Frontmatter contains the YAML frontmatter of a rule.
type ParseErrors ¶
type ParseErrors struct {
Errors []error
}
ParseErrors collects multiple parse errors when loading rules from a directory. Individual parse failures don't prevent other rules from loading.
func (*ParseErrors) Error ¶
func (e *ParseErrors) Error() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages rules from multiple sources with precedence handling. Precedence (highest to lowest): project > personal > team Key is the relative path (e.g., "api/rest.md", "security.md")
func LoadRegistry ¶
LoadRegistry creates a registry by loading rules from all sources. Empty string for any directory means that source is not available.
func (*Registry) Add ¶
Add adds a rule to the registry. Higher precedence sources (project > personal > team) override lower ones.
func (*Registry) All ¶
All returns all unique rules (highest precedence version of each), sorted by relative path for deterministic ordering.
type Rule ¶
type Rule struct {
Frontmatter // Embedded; access paths via rule.Frontmatter.Paths or rule.Paths
Name string // Derived from filename (e.g., "security" from "security.md")
Body string // Markdown content after frontmatter
Source Source // Where this rule came from
FilePath string // Absolute path to the rule file
RelPath string // Relative path within rules/ (preserves subdirs, e.g., "api/rest.md")
}
Rule represents a staghorn rule file.
func LoadFromDirectory ¶
LoadFromDirectory loads all rules from a directory (recursive). Parse errors for individual files are collected in the returned ParseErrors slice but do not prevent other rules from loading.
func (*Rule) HasPathScope ¶
HasPathScope returns true if the rule has path-specific scope.