rules

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: GPL-3.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	Filename       = "COMMITBRIEF.md"
	OutputFilename = "OUTPUT.md"
	LocalSubdir    = ".commitbrief"
)
View Source
const (
	// RuleOther is the K4 fallback: an empty, unknown or unparseable
	// rule_id resolves here.
	RuleOther = "general.other"
	// RuleTestFlaky is always emitted by the static flaky pre-pass
	// (internal/flaky, ADR-0022).
	RuleTestFlaky = "test.flaky"
	// RuleHardcodedSecret is always emitted by `commitbrief leaks`
	// (ADR-0036).
	RuleHardcodedSecret = "sec.hardcoded-secret"
)

Rule ids that other packages reference directly: the fallback bucket and the two deterministic producers that never ask the model.

View Source
const RepairJSONComplete = `` /* 241-byte string literal not displayed */

RepairJSONComplete is the recovery directive for truncated / malformed JSON (ParseErrMalformedJSON): ask the model to finish and correct the document.

View Source
const RepairPrevOutputTemplate = "Your previous response, which failed to parse, was:\n```\n%s\n```\nReturn the complete corrected JSON object now."

RepairPrevOutputTemplate embeds the previous (partial) output in the repair user prompt so the model can complete it. Single %s for the prior response. The Provider interface is single-shot (ADR-0014); "continue" must be a fresh request carrying the partial output, not a multi-turn continuation.

View Source
const RepairSchemaReset = `` /* 288-byte string literal not displayed */

RepairSchemaReset is the recovery directive for prose / schema-ignored output (ParseErrEmpty, ParseErrSchema): a hard "JSON only" reset.

View Source
const TaxonomyVersion = 1

TaxonomyVersion is the version of the closed rule taxonomy (ADR-0045). Ids are only ever added: an id is never removed or renamed, because policy files and inline suppression markers refer to them. A renamed id keeps resolving through ruleAliases instead.

Variables

This section is empty.

Functions

func Build

func Build(rulesLoaded Loaded, langRes lang.Resolution, archContext string) (system, userTpl string)

Build assembles the system prompt from the user's review rules and then appends the fixed severity rubric, the JSON-contract response format, the language directive, and the prompt-injection guard. ADR-0014 §1-2 govern the prompt shape — the LLM's only output channel is the JSON findings document; OUTPUT.md no longer participates in prompt construction (it has become a client-side renderer template).

archContext (ADR-0030), when non-empty, inserts an <architecture_constraints> block between the rules and the rubric so the reviewer can flag diffs that cross a declared import boundary. Empty (the default / no architecture.json) emits nothing, keeping the system prompt — and therefore the cache key — byte-identical to a pre-ADR-0030 run.

func BuildPlainText added in v0.9.0

func BuildPlainText(rulesLoaded Loaded, langRes lang.Resolution, archContext string) (system, userTpl string)

BuildPlainText is the system-prompt variant for CLI-based providers (claude-cli, gemini-cli, …). Same project rules and severity rubric as Build, but swaps the JSON-contract response format for a fixed plain-text layout the host CLI can produce and we can stream straight to stdout — no JSON parsing, no findings struct.

Used when the active provider satisfies provider.PlainTextEmitter. The user prompt template (`userTpl`) is shared with Build so the review pipeline (cache key, token estimation) doesn't branch on mode. archContext (ADR-0030) is injected the same way as in Build.

func IsValidRuleID added in v1.19.0

func IsValidRuleID(id string) bool

IsValidRuleID reports whether id is a canonical taxonomy id.

func NormaliseRuleID added in v1.19.0

func NormaliseRuleID(raw string) (id string, fallback bool)

NormaliseRuleID resolves a model-supplied rule_id to a canonical id: trim, lowercase, alias table, then membership. Empty and unknown values become RuleOther. fallback reports whether the result is the fallback because the input was empty or unknown (an input that literally said "general.other" is not counted) so the caller can log how many findings were normalised.

func RuleIDs added in v1.19.0

func RuleIDs() []string

RuleIDs returns every id in canonical order.

Types

type Loaded

type Loaded struct {
	Content string
	Source  Source
	Path    string
	Hash    string
}

func Default

func Default() Loaded

func DefaultOutput

func DefaultOutput() Loaded

func Load

func Load(repoRoot string) (Loaded, error)

func LoadOutput

func LoadOutput(repoRoot, userHome string) (Loaded, error)

LoadOutput resolves the output-format template through a three-tier fallback: repo-local (<repoRoot>/.commitbrief/OUTPUT.md) → user-level (<userHome>/.commitbrief/OUTPUT.md) → binary-embedded default. Both path segments are gitignored by `commitbrief setup --local`, so the override is per-user rather than team-shared — output convention is considered a personal preference; team-shared review content stays in COMMITBRIEF.md.

Pass userHome == "" to skip the user-level layer (test injection); the CLI passes os.UserHomeDir() as resolved at startup.

type Rule added in v1.19.0

type Rule struct {
	ID         string
	Definition string
	Level      RuleLevel
}

Rule is one entry of the closed taxonomy.

func LookupRule added in v1.19.0

func LookupRule(id string) (Rule, bool)

LookupRule returns the rule for a canonical id.

func Taxonomy added in v1.19.0

func Taxonomy() []Rule

Taxonomy returns a copy of the rule list in its canonical order.

func (Rule) Category added in v1.19.0

func (r Rule) Category() string

Category returns the part of the id before the dot ("sec", "perf", ...).

type RuleLevel added in v1.19.0

type RuleLevel string

RuleLevel is a rule's default SARIF level. It is independent of a finding's severity: the level only feeds a SARIF rule's defaultConfiguration.

const (
	LevelError   RuleLevel = "error"
	LevelWarning RuleLevel = "warning"
	LevelNote    RuleLevel = "note"
)

type Source

type Source int
const (
	SourceDefault Source = iota
	SourceFile
	SourceUserFile
)

func (Source) String

func (s Source) String() string

Jump to

Keyboard shortcuts

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