{"modulePath":"github.com/CommitBrief/commitbrief","version":"v1.23.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package rules\n\n## Constants\n\n```go\nconst (\n\tFilename       = \"COMMITBRIEF.md\"\n\tOutputFilename = \"OUTPUT.md\"\n\tLocalSubdir    = \".commitbrief\"\n)\n```\n\n```go\nconst (\n\t// RuleOther is the K4 fallback: an empty, unknown or unparseable\n\t// rule_id resolves here.\n\tRuleOther = \"general.other\"\n\t// RuleTestFlaky is always emitted by the static flaky pre-pass\n\t// (internal/flaky, ADR-0022).\n\tRuleTestFlaky = \"test.flaky\"\n\t// RuleHardcodedSecret is always emitted by `commitbrief leaks`\n\t// (ADR-0036).\n\tRuleHardcodedSecret = \"sec.hardcoded-secret\"\n)\n```\nRule ids that other packages reference directly: the fallback bucket and the two deterministic producers that never ask the model.\n\n```go\nconst RepairJSONComplete = `Your previous response was not valid JSON — it was truncated or malformed. Return the COMPLETE, corrected JSON object matching the \u003cresponse_format\u003e schema above, in full. Output JSON only: no prose, no markdown code fences, no commentary.`\n```\nRepairJSONComplete is the recovery directive for truncated / malformed JSON (ParseErrMalformedJSON): ask the model to finish and correct the document.\n\n```go\nconst RepairPrevOutputTemplate = \"Your previous response, which failed to parse, was:\\n```\\n%s\\n```\\nReturn the complete corrected JSON object now.\"\n```\nRepairPrevOutputTemplate 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.\n\n```go\nconst RepairSchemaReset = `Your previous response did not parse as valid findings JSON. Output ONLY a single JSON object matching the \u003cresponse_format\u003e schema above — no prose, no markdown code fences, no commentary before, after, or between objects. If there are no review-worthy issues, return {\"findings\": []}.`\n```\nRepairSchemaReset is the recovery directive for prose / schema-ignored output (ParseErrEmpty, ParseErrSchema): a hard \"JSON only\" reset.\n\n```go\nconst TaxonomyVersion = 1\n```\nTaxonomyVersion 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.\n\n## Functions\n\n```go\nfunc Build(rulesLoaded Loaded, langRes lang.Resolution, archContext string) (system, userTpl string)\n```\nBuild 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).\n\narchContext (ADR-0030), when non-empty, inserts an \\\u003carchitecture\\_constraints\u003e 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.\n\n```go\nfunc BuildPlainText(rulesLoaded Loaded, langRes lang.Resolution, archContext string) (system, userTpl string)\n```\nBuildPlainText 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.\n\nUsed 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.\n\n```go\nfunc IsValidRuleID(id string) bool\n```\nIsValidRuleID reports whether id is a canonical taxonomy id.\n\n```go\nfunc NormaliseRuleID(raw string) (id string, fallback bool)\n```\nNormaliseRuleID 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.\n\n```go\nfunc RuleIDs() []string\n```\nRuleIDs returns every id in canonical order.\n\n## Types\n\n```go\ntype Loaded struct {\n\tContent string\n\tSource  Source\n\tPath    string\n\tHash    string\n}\n```\n\n```go\nfunc Default() Loaded\n```\n\n```go\nfunc DefaultOutput() Loaded\n```\n\n```go\nfunc Load(repoRoot string) (Loaded, error)\n```\n\n```go\nfunc LoadOutput(repoRoot, userHome string) (Loaded, error)\n```\nLoadOutput resolves the output-format template through a three-tier fallback: repo-local (\\\u003crepoRoot\u003e/.commitbrief/OUTPUT.md) → user-level (\\\u003cuserHome\u003e/.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.\n\nPass userHome == \"\" to skip the user-level layer (test injection); the CLI passes os.UserHomeDir() as resolved at startup.\n\n```go\ntype Rule struct {\n\tID         string\n\tDefinition string\n\tLevel      RuleLevel\n}\n```\nRule is one entry of the closed taxonomy.\n\n```go\nfunc LookupRule(id string) (Rule, bool)\n```\nLookupRule returns the rule for a canonical id.\n\n```go\nfunc Taxonomy() []Rule\n```\nTaxonomy returns a copy of the rule list in its canonical order.\n\n```go\nfunc (r Rule) Category() string\n```\nCategory returns the part of the id before the dot (\"sec\", \"perf\", ...).\n\n```go\ntype RuleLevel string\n```\nRuleLevel is a rule's default SARIF level. It is independent of a finding's severity: the level only feeds a SARIF rule's defaultConfiguration.\n\n```go\nconst (\n\tLevelError   RuleLevel = \"error\"\n\tLevelWarning RuleLevel = \"warning\"\n\tLevelNote    RuleLevel = \"note\"\n)\n```\n\n```go\ntype Source int\n```\n\n```go\nconst (\n\tSourceDefault Source = iota\n\tSourceFile\n\tSourceUserFile\n)\n```\n\n```go\nfunc (s Source) String() string\n```\n\n","path":"github.com/CommitBrief/commitbrief/internal/rules","name":"rules","synopsis":"","isRedistributable":true}
