Skip to content

Concepts

Configuration

Every configuration key Fensu reads, how it discovers config, and how to override thresholds and contracts.

Fensu is configured with fensu.toml or [tool.fensu] in pyproject.toml. Configuration declares the scopes Fensu scans, the rules it runs, and any threshold, exception, or contract overrides.

fensu check, fensu rule, and fensu skills search upward from the current directory for:

  1. fensu.toml
  2. pyproject.toml containing [tool.fensu]

The nearest directory wins, and fensu.toml takes precedence over pyproject.toml in the same directory. The first source found is used whole; sources are never merged.

fensu.toml
roots = ["src/my_package"]
tests = ["tests"]
tooling = ["scripts"]
select = ["FF"]
[thresholds]
max_positional_args = 1

Flat top-level keys configure a single Python project. Use explicit [targets.<name>] tables for multiple projects or Rust, TypeScript, and Svelte analyzers:

[targets.backend]
analyzer = "python"
root = "."
roots = ["src/acme"]
ownership_roots = ["src/acme/sources/*", "src/acme/runtime"]
tests = ["tests"]
select = ["FF"]
[targets.web]
analyzer = "svelte"
root = "frontend"
roots = ["src"]
tests = ["tests"]
test_layout = "mirrored"
rule_packs = ["sveltekit"]
select = ["FPSK"]
[targets.rust]
analyzer = "rust"
roots = ["crates"]
tests = []
tooling = ["crates/project-tools"]
rule_packs = ["rust"]
select = ["FPRS"]

Each target requires analyzer (python, rust, typescript, or svelte) and roots. root defaults to . and resolves the target’s paths relative to the configuration directory. Explicit targets cannot be mixed with flat top-level keys except top-level [repository_rules] (see Repository rules). fensu check runs every target unless --target NAME selects one.

Web targets also accept test_layout, ui_kit, shadcn, openapi, and generated (see TypeScript and SvelteKit). Rust targets discover Cargo workspace members automatically (see Rust).

Fensu fails closed on invalid configuration rather than silently dropping typos:

  • Unknown keys, missing roots, missing paths on disk, nested or overlapping roots, and duplicate scope package names are rejected.
  • A rule cannot appear in both select and warn, or both warn and ignore.
  • All thresholds, role names, pack names, rule options, globs, and required reason fields are validated before evaluation starts.
KeyTypeDefaultPurpose
targetstable of tablesnoneNamed analyzer targets; mutually exclusive with flat keys.
repository_rulestablenoneCross-target custom-rule policy for named targets.
rootslist of stringsrequiredProduct code scopes (no nesting or overlap).
ownership_rootslist of stringsanalyzer-specificDirectories below which domains and subdomains begin.
testslist of strings["tests"]Test scopes.
test_scopeslist of strings["unit", "integration", "e2e"]Allowed directory names directly under a test root.
toolinglist of strings[]Dev tooling scopes.
selectlist of selectorscomplete analyzer policyBlocking rules to enable.
warnlist of selectors[]Advisory rules evaluated by fensu check --warn.
ignorelist of selectors[]Rule codes to disable.
rule_pathslist of strings[]Directories or files of Python custom rules to load.
rule_moduleslist of strings[]Importable Python modules holding custom rules.
rule_packslist of strings[]Fensu-shipped native policies to activate.
rule_optionsrule-code tablesdeclared defaultsPer-rule option overrides.
thresholdstableshipped defaultsGlobal threshold overrides.
threshold_overridesarray of tables[]Path-scoped threshold overrides with reason.
rule_exceptionsarray of tables[]Exact rule/file (and optional symbol) exceptions with reason.
rule_ignoresarray of tables[]Path-scoped rule suppressions with reason.
evaluationtableall discovered filesDirect evaluation include / exclude globs.
cachetablecaching onPersistent result cache settings for fensu check.
custom_host_timeout_secondsinteger (1–600)30Custom-rule timeout for Rust, TypeScript, and Svelte targets.
skillstableinferred identityGenerated agent-skill settings.
rolestable of tablesnonePer-role threshold overrides.
contractstableten shipped patternsFunction-name glob to behavior contracts.

roots declares which product code Fensu scans; ownership_roots declares where domain ownership begins inside that tree when structural grouping directories sit above domains:

[targets.app]
analyzer = "python"
roots = ["src/example"]
ownership_roots = ["src/example/sources/*", "src/example/runtime"]
src/example/
├── sources/ # structural group
│ ├── region_a/ # ownership root
│ │ ├── orders/main/process.py
│ │ └── partners/importing/main/load.py
│ └── region_b/ # ownership root
│ └── inventory/main/refresh.py
└── runtime/ # ownership root
└── observability/main/report.py

Patterns are target-relative POSIX globs supporting *, standalone **, and brace alternatives (src/example/{sources/*,runtime}). Deepest concrete root wins; equal-specificity overlaps, unmatched patterns, unused roots, and roots crossing main/, _helpers/, or classes/ fail closed. Structural directories above or at an ownership root cannot hold role files directly.

Defaults when omitted:

AnalyzerDefault ownership roots
PythonEach configured product root.
TypeScript and SvelteThe lib/ directory below each product root.
RustCargo-inferred crate source roots.

select, warn, and ignore accept rule-code prefixes or exact codes:

SelectorMatches
FF / FFR / FFR3 / FFR301All core rules, one family, one bucket, or one exact rule.
FP / FPTS / FPSK / FPRS / FPDGAll activated native packs, or one pack namespace (FPDGA = Dagster annotation aliases).
X / XDB / XDB001All custom rules, one namespace, or one custom rule.

select defaults to ["FF"] for Python and ["FP"] for Rust, TypeScript, and Svelte targets (Rust activates rust automatically; web packs must be listed in rule_packs).

select = ["FFL", "FFR", "FFS", "FFN", "FFH", "FFT"]
ignore = ["FFH007", "FFA103"] # ignore always wins over select
  • A rule runs when it is enabled by default and matches select, or is named by its exact code in select (the only way to enable opt-in rules such as FFS102).
  • ignore always wins over select.
  • Activating a pack in rule_packs makes its catalogue available; select its prefix separately.

warn defines an advisory ruleset evaluated only with fensu check --warn. Warnings are reported after faults and never affect the exit code:

select = ["FFL", "FFR", "FFS", "FFN", "FFH", "FFT"]
warn = ["FFA"]

A resolved rule cannot appear in both select and warn, or both warn and ignore.

Use [[rule_exceptions]] for an unavoidable finding in one exact file. Add symbols to narrow the waiver to named functions or methods:

[[rule_exceptions]]
rule = "FFS120"
path = "src/my_package/integrations/_helpers/callbacks.py"
symbols = ["ProgressCollector.update"]
reason = "The external API invokes this callback positionally."

Omit symbols to waive matching findings across the whole file (symbols = [] is rejected). Rule code, repository-relative file path, and symbols must be exact (no globs or line numbers). Every exception and listed symbol must suppress a fault; stale exceptions fail fensu check. Rust uses item paths such as Record::load (see Rust).

Use [[rule_ignores]] to suppress findings for matching rule selectors and path globs while keeping the rules and project context active:

[[rule_ignores]]
rules = ["FFA", "XGENERATED"]
paths = ["src/my_package/generated/**", "conftest.py"]
reason = "Generated interfaces are checked by their source schema."

A finding is suppressed only when one entry matches both its rule code and its reported path. Applies to both blocking and --warn runs. Path-scoped ignores are not stale-checked; exact rule_exceptions are validated first so a broad ignore cannot hide a stale exact waiver.

[evaluation] narrows which discovered files receive direct rule execution during gradual adoption:

[evaluation]
include = ["src/my_package/compiler/**", "tests/unit/src/my_package/compiler/**"]
exclude = ["src/my_package/compiler/generated/**"]
ConfigurationDirect evaluation targets
Neither keyEvery discovered source file.
exclude onlyEvery discovered file except excluded matches.
include onlyOnly included matches.
include and excludeIncluded matches minus excluded matches (exclude wins).

Every include glob must match at least one discovered file and leave at least one target; unmatched excludes are allowed. Excluded files remain part of project context for imports, ownership resolution, and fensu map. fensu check reports target and discovery counts when filtering is active.

ControlEffect
roots, tests, toolingDefine the discovered project universe and each file’s scope.
warnReport matching rules as nonblocking advice with fensu check --warn.
ignoreDisable matching rules globally.
rule_exceptionsWaive one exact file or symbol finding and fail when stale.
rule_ignoresKeep rules and context active while suppressing matching selector/path findings.
evaluation.include / excludeRestrict which discovered files receive direct rule execution.

test_scopes lists the allowed top-level directories under a test root (default ["unit", "integration", "e2e"]). Setting it replaces the default:

test_scopes = ["unit", "integration", "e2e", "real"]

Entries must be unique, non-empty lowercase directory names. FFT002 rejects unlisted directories so typos such as tests/uint/ never go unchecked.

[thresholds] overrides shipped numeric limits globally (see Default thresholds for all names and defaults; 0 disables min_* thresholds):

[thresholds]
max_statements = 50
max_positional_args = 1
max_file_lines = 1500

[roles.<role>] overrides thresholds for one fixed Fensu role (main, helpers, classes, models, types, constants, exceptions, entry):

[roles.entry]
max_statements = 30

[[threshold_overrides]] overrides thresholds for matching fault paths (most specific glob wins; ties go to the later entry; beats [roles] and [thresholds]):

[[threshold_overrides]]
paths = ["src/my_package/reporting/**"]
thresholds = { max_file_lines = 3000 }
reason = "Generated report tables exceed the default line budget."

Each entry requires paths (repository-relative POSIX globs), thresholds (non-negative integers), and a non-empty reason. For container and package size rules (max_helpers_container_buckets, max_crate_code_lines), match the reported path (_helpers/__init__.py, package __init__.py, or Cargo.toml).

[contracts] maps function-name globs to naming-family behaviors:

BehaviorRuleRequirement
no-returnFFN001Do not return a meaningful value.
returns-boolFFN002Declare bool, TypeGuard, or TypeIs.
returns-valueFFN003Do not explicitly declare None.
returns-iteratorFFN004Yield or declare an iterator or generator return.

Shipped defaults: validate_* and enforce_* (no-return); is_*, has_*, can_*, supports_* (returns-bool); get_*, to_*, as_* (returns-value); iter_* (returns-iterator). Add project patterns directly:

[contracts]
"write_*" = "no-return"
"yield_*" = "returns-iterator"

Conflicting patterns on one function fail configuration. For other behaviors, write a custom rule.

rule_packs activates shipped native policies (dagster, typescript, sveltekit, rust):

rule_packs = ["dagster"]
select = ["FPDG"]

See Native rule packs and the Dagster, TypeScript and SvelteKit, and Rust pages for pack rules and options.

rule_paths (directories or .py files loaded in isolation) and rule_modules (importable repository modules) load @rule-decorated checks into the same catalogue as core and pack rules:

tooling = ["scripts"]
rule_paths = ["scripts/fensu_policy/rules"]
rule_modules = ["company_architecture.rules"]
select = ["FF", "XAC001"]

See Custom rules for the authoring API.

Override typed rule options by exact rule code; only overrides belong in TOML (defaults live in rule definitions, and list overrides become immutable tuples):

[rule_options.XAC001]
allowed_names = ["alpha", "beta"]
strict = true

Fensu validates all [rule_options.*] tables against the full catalogue before evaluation, including unselected rules.

[cache] ([tool.fensu.cache] in pyproject.toml) controls the persistent result cache used by fensu check:

KeyTypeDefaultPurpose
enabledbooleantruePersist and reuse per-file results between runs.
require_cacheablebooleanfalseVerify selected custom rules use only tracked inputs so runs stay cached.

Override for a single run with --cache or --no-cache. See Keeping custom rules cacheable.

[skills] sets the project slug used by fensu skills (for example .agents/skills/fensu-acme-api/SKILL.md):

[skills]
name = "acme-api"

When omitted, Fensu infers the name from [project].name in pyproject.toml, then the configuration directory name.

Fensu checks both its Python and Rust codebases with named targets:

[targets.python]
analyzer = "python"
roots = ["src/fensu"]
tests = ["tests"]
tooling = ["scripts"]
select = ["FF"]
[targets.rust]
analyzer = "rust"
roots = ["crates"]
tests = []
tooling = ["crates/fensu-rust"]
rule_packs = ["rust"]
select = ["FPRS"]