{"modulePath":"github.com/codefit-cli/codefit","version":"v0.2.9","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package ruleengine\n\nPackage ruleengine is codefit's own matcher for a subset of the Semgrep rule format (PRD section 17). Deterministic detection rules are written as declarative YAML (the de-facto standard, with a large community corpus) and matched in pure Go over the provider's AST — the OCaml Semgrep/OpenGrep engine is NOT embedded, which would break the single, CGO-free binary.\n\nSupported operators (the core subset): pattern, pattern-either, patterns, pattern-not, pattern-inside, metavariables ($VAR), metavariable-regex. Deliberately NOT supported: taint mode and pattern-sources/sinks/sanitizers — their role is covered by the agent reasoning over mapped surface.\n\nStatus: BUILT (Fase 1). The rule shape ([Rule](#Rule)), the YAML loader, and the matcher itself ([Compile](#Compile), [Match](#Match), [Matches](#Matches)) are implemented, and the TypeScript provider runs its deterministic security rules through them. Note the shape: the matcher is package-level FUNCTIONS over [syntax.Node](/github.com/codefit-cli/codefit/internal/core/syntax#Node), not the [Engine](#Engine) interface — [Engine](#Engine) is a declared contract that nothing implements today, kept for the per-language adapter it was drawn for. Do not read it as the entry point.\n\n## Functions\n\n```go\nfunc Match(rules []CompiledRule, root syntax.Node, file string) []findings.Finding\n```\nMatch runs the compiled rules over the tree rooted at root and returns the findings, located by file and line. file is the project-relative path.\n\n```go\nfunc Matches(pattern, code syntax.Node) (map[string]string, bool)\n```\nMatches reports whether the (already-parsed) pattern node matches the code node structurally, returning the metavariable bindings (name -\u003e matched source text). It is the core of the matcher and is exported so each operator can be tested against real trees.\n\nMatching is purely structural — no ellipsis (PRD §17 subset): a metavariable matches any node (and binds, consistently across repeats); otherwise node types must be equal and named children must match pairwise; leaves compare by text.\n\n## Types\n\n```go\ntype CompiledRule struct {\n\t// contains filtered or unexported fields\n}\n```\nCompiledRule is a Rule whose pattern strings have been parsed to syntax.Node (once, at load time) and whose metavariable regexes are compiled. The ruleengine never parses source itself — Compile receives a parse function from the active provider, so the engine stays parser-agnostic.\n\n```go\nfunc Compile(rules []Rule, parse func(src string) (syntax.Node, error)) ([]CompiledRule, error)\n```\nCompile parses each rule's pattern(s) via parse (a provider's parser, which emits syntax.Node) and compiles the metavariable regexes.\n\n```go\ntype Engine interface {\n\t// Match runs the rules against a parsed AST and returns the findings.\n\tMatch(rules []Rule, ast any) ([]findings.Finding, error)\n}\n```\nEngine matches rules against a parsed file and emits deterministic findings.\n\nNOT IMPLEMENTED by anything today: the working matcher is the package-level [Compile](#Compile)/[Match](#Match) pair over [syntax.Node](/github.com/codefit-cli/codefit/internal/core/syntax#Node). This interface is kept for the per-language AST adapter it was drawn for, which is why its ast argument is still abstract (any).\n\n```go\ntype Rule struct {\n\tID         string             `yaml:\"id\"`\n\tMessage    string             `yaml:\"message\"`\n\tSuggestion string             `yaml:\"suggestion\"`\n\tSeverity   findings.Severity  `yaml:\"severity\"`\n\tDimension  findings.Dimension `yaml:\"dimension\"`\n\n\t// Operators (core subset). Exactly the set codefit's matcher supports.\n\tPattern           string            `yaml:\"pattern,omitempty\"`\n\tPatternEither     []string          `yaml:\"pattern-either,omitempty\"`\n\tPatterns          []string          `yaml:\"patterns,omitempty\"`\n\tPatternNot        string            `yaml:\"pattern-not,omitempty\"`\n\tPatternInside     string            `yaml:\"pattern-inside,omitempty\"`\n\tMetavariableRegex map[string]string `yaml:\"metavariable-regex,omitempty\"`\n}\n```\nRule is a deterministic detection rule in the supported Semgrep-format subset (PRD section 17). A rule carries its finding metadata plus one or more pattern operators; the operators are mutually composable (patterns = AND of its members, PatternEither = OR, etc.).\n\n```go\nfunc LoadFS(fsys fs.FS, dir string) ([]Rule, error)\n```\nLoadFS reads and validates every \\*.yaml rule file under dir in fsys and returns the rules in a stable, file-sorted order. fsys is supplied by the caller (the embedded rules/ FS in production, an in-memory FS in tests), so the engine never reaches the real filesystem itself.\n\nValidation is strict and located: a malformed file or a structurally invalid rule fails with an error naming the file (and the rule id when known), so a broken rule can never enter the engine silently — a silent rule is a silent vulnerability.\n\n","path":"github.com/codefit-cli/codefit/internal/core/ruleengine","name":"ruleengine","synopsis":"Package ruleengine is codefit's own matcher for a subset of the Semgrep rule format (PRD section 17).","isRedistributable":true}
