Metadata-Version: 2.4
Name: kvb-quality
Version: 1.5.0
Summary: One language-agnostic quality gate for staged changes and whole repositories
Author-email: Kevin Veen-Birkenbach <kevin@veen.world>
License-Expression: MIT
Project-URL: Homepage, https://github.com/infinito-nexus/quality
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyYAML
Requires-Dist: pathspec
Dynamic: license-file

# quality

Homepage: https://github.com/infinito-nexus/quality

## Install

`flake.lock` is the only pin source ([requirement 001](docs/requirements/scan/001-language-agnostic-quality-check.md), decision 18). On a host with Nix, install `packages.default`, the runner wrapped with every tool by absolute store path, and call it by absolute path:

```sh
nix profile install github:infinito-nexus/quality/<release-tag>
~/.nix-profile/bin/quality check --staged
```

### Agent skills

The `kvb-quality-*` analysis skills ([requirement 003](docs/requirements/audit/003-analysis-skills-in-quality.md)) install from a checkout:

```sh
make install
```

It mirrors `skills/kvb-quality-*` into `~/.claude/skills`, `~/.agents/skills` and, when `~/.codex` exists, `~/.codex/skills`; installs the checkout into `~/.local/share/kvb-quality/venv`; and writes `~/.local/bin/kvb-quality-python`, the interpreter every skill script starts with.

`kvb-quality-audit` ([requirement 011](docs/requirements/audit/011-release-security-audit.md)) audits the code a release changes and writes one attestation per tree; skills' `kvb-release-cut` runs it before every release. Its `upstream/` folder is Cloudflare's [security-audit-skill](https://github.com/cloudflare/security-audit-skill), MIT, vendored unchanged at a pinned commit with its licence; see `skills/kvb-quality-audit/README.md`.

## Dev stack

Hosts without Nix, CI and dev stacks use `packages.image` (`nix build .#image`), the OCI image of the same closure, published to ghcr by digest; the digest is in the release notes. A dev stack adds it as a compose service under the profile `tools` and a make target that runs it:

```yaml
services:
  quality:
    image: ghcr.io/infinito-nexus/quality@sha256:<digest>
    profiles: [tools]
    network_mode: none
    read_only: true
    tmpfs: [/tmp]
    user: "65534"
    working_dir: /src
    volumes:
      - .:/src:ro
```

```make
quality-check:
	docker compose --profile tools run --rm quality check --staged
```

`--staged` needs no database. `--base` and `--all` add the deep tier, which reads the bundle of `quality db update`: mount it with `- <db>:/db:ro` and pass `--db /db`. `--rule <id>`, repeatable, runs only the named catalogue rules in any of the three modes, the checks the runner does itself and `.qualityignore.yml` staleness included; the database is then needed only when a named rule is of the deep tier, so `quality check --base origin/main --rule test.text-presence` runs without `--db`, and an id outside the catalogue stops the check with exit 2. `quality db update --licenses <repo>`, repeatable, also stores the registry licences of the exact pins at each named repository's HEAD and in its staging index for `legal.dependency-license`; a pin without an SPDX licence there stays `unchecked`, and an update without `--licenses` keeps the stored licences. Run the service from a main checkout, because a linked worktree's `.git` file points outside `/src`.

## Image scan

`quality image <ref|archive|dir>... [--json]` scans container images with Trivy and osv-scanner, offline, on the bundle of `quality db update` ([requirement 010](docs/requirements/scan/010-image-vulnerability-scan.md)). It writes one `security.vulnerable-image` finding per vulnerable package and image, in the schema of `quality check --json` plus `package`, `installed`, `fixed`, `vulnerabilities`, `engines` and `message`, and exits 1 when an image has a finding or stays unscanned.

- **Local only**: quality never pulls. A reference is exported from the local Docker daemon with `docker save`, once per image id; a `docker save` tar or an OCI layout directory is read as it is. A reference the daemon does not hold is listed as unscanned with the reason `not local`, as is an image an engine could not read, with the engine's first error line.
- **Bundle**: `quality db update` fetches Trivy's vulnerability and Java databases and the osv-scanner databases of every ecosystem in `rules/tools.yml`, the Debian, Alpine and Ubuntu packages included; an image with JAR files stays unscanned on a bundle without the Java database, so update a bundle older than v1.2.0 first.
- **Pull limits stay with the caller**: pull the images first, through a registry mirror or a pull-through cache, so a scan of many images costs no registry quota.

```sh
docker pull mirror.example/library/nginx:1.27
quality image mirror.example/library/nginx:1.27 ./build/app.tar --json > images.json
quality image report images.json ci-images.json
```

`quality image report <json>... [--json]` reduces such reports to one row per image, keyed by the last path segment and the tag, so `registry.example/x/nginx:1.27` and `mirror.example/nginx:1.27` join. A row shows the image, tag, its distinct ids per severity (`C`, `H`, `M`, `L`, `?`), the ids with a fixed-in version over all ids with the two packages that fix the most and their highest fixed-in version, the ids without a fix and the engines; unscanned images follow in their own list. It proposes no fix: bumping, rebuilding and suppressing stay with the caller.

## CI

Another repository calls the reusable workflows by the commit of a release tag. Each workflow builds its tools from the flake at the commit it is called at (`job.workflow_sha`), so that `uses:` line is the only pin, and Dependabot's `github-actions` ecosystem moves it to the next release. `quality.yml` gates the range a pull request or push adds and scans every commit of it for secrets; `tool.yml` runs one tool of the flake, under its package name, over the whole tree:

```yaml
jobs:
  quality:
    uses: infinito-nexus/quality/.github/workflows/quality.yml@<commit> # <release-tag>
  ruff:
    uses: infinito-nexus/quality/.github/workflows/tool.yml@<commit> # <release-tag>
    with:
      tool: ruff
      args: check src tests
```

## Layer contracts

A repository that holds `.quality/architecture.yml` gets the rules `architecture.layer` and `architecture.cycle` ([requirement 005](docs/requirements/score/005-architecture-score.md), decision 3); each new hit lowers the architecture score by 25. Python runs through `lint-imports` of import-linter, JavaScript through `depcruise` of dependency-cruiser, both bundled like every other tool. Each section is optional, every key inside it is required, and a malformed file stops the check with an error naming the key. `source` is the directory holding the code, `.` for the root, and for JavaScript also the scope of the cycle check; `layers` lists the highest layer first, and no layer may import one above it:

```yaml
python:
  source: src
  packages: [shop]
  layers: [shop.web, shop.domain]
  forbidden:
    - {from: [shop.domain], to: [shop.web]}
javascript:
  source: web
  layers: [web/ui, web/core]
  forbidden: []
```

## Pins

Pin discovery and `.quality/pins.yml` are the input of the `version.*` rules that sub-wave 1a of [requirement 017](docs/requirements/rules/017-generic-checks-from-core.md) adds (decision 3); no rule reads them yet, so `quality check` neither reads the file nor fails on it today. Discovery finds pins by itself: each `FROM` of a Dockerfile or Containerfile, `services.*.image` of a compose file (`compose.yml`, `docker-compose.*.yaml` and their templates), and `jobs.*.container` and the job and step `uses:` of a workflow. A value built from a variable or a Jinja tag pins nothing. A repository whose pins live elsewhere declares them in `.quality/pins.yml`: `sources` lists entries of `files` (globs in `.gitignore` syntax) and the keys of one mapping that hold the image, `image`, and its version, `version`, at least one of the two; `waiver`, optional, is the regex of the repository's own marker that keeps a pin as it is, matched on the pin's line or the nearest non-blank line above it. Discovery refuses a malformed file with an error naming the key:

```yaml
sources:
  - files: [roles/*/meta/services.yml]
    image: image
    version: version
waiver: 'nocheck:\s*docker-version'
```

The `dockerfile` kind holds `Dockerfile`, `Containerfile`, `<name>.Dockerfile`, `Dockerfile.<variant>` such as `Dockerfile.ci` or `Containerfile.base`, and their `.j2` templates (decision 8). hadolint reads plain files only; quality's own Dockerfile enforcers read a template with every Jinja tag blanked, so its lines and columns stay those of the template.

## Conventions

The `convention.*` rules check house style and run in every repository (decision 6). `.quality/conventions.yml` turns them off: `enabled: false` silences all of them, `disabled` lists single rule ids, each of which must name a catalogue `convention.*` rule. Each side of a `--base` check reads its own file, and a malformed one stops the check with exit 2:

```yaml
enabled: false
```

## Waivers

A comment on the finding's line waives it: `nocheck: <rule> -- <reason>` in any comment syntax, where a group such as `coding` names all its rules. A `.nocheck` file waives rules for its folder and every folder below it, one `# nocheck: <rule> -- <reason>` per line; a line naming nothing in the catalogue is left to the project's own lints, and a catalogue line without a reason stops the check with exit 2. Hard and changed_only rules are waived only in `.qualityignore.yml`, whose `--base` entries come from the base side, so a change cannot waive its own finding there: a `.nocheck` line naming a group waives only its other rules, and one naming nothing else exits 2. `--all` stops on a `.nocheck` or `.qualityignore.yml` entry that waives nothing.

A repository with its own waiver markers declares their spelling in `.quality/comments.yml` ([requirement 007](docs/requirements/rules/007-repo-directive-spellings.md)): `directives` lists groups in the schema of `rules/comments.yml` (`tool`, `spellings`, optional `languages`, `marker`, `tight`, `position`), whose comments `clean.comment` then accepts, and `pragmas_allowed` lists the tool pragmas `clean.tool-pragma` lets through. A declared directive waives nothing; each side of a `--base` check reads its own file, and a malformed one stops the check with exit 2:

```yaml
directives:
  - tool: core lint waivers
    spellings: ['nocheck:\s*[a-z0-9-]+(?:,\s*[a-z0-9-]+)*']
pragmas_allowed: ['noqa:\s*[A-Z]+\d+(?:,\s*[A-Z]+\d+)*']
```

`clean.em-dash` refuses an added em dash in every text kind ([requirement 008](docs/requirements/rules/008-no-em-dash.md)); translation catalogues (`.po`) have no kind and stay out.

`clean.embedded-code` flags a body of two or more non-blank lines handed to an interpreter as text ([requirement 018](docs/requirements/rules/018-embedded-code.md)): the code argument of `sh`, `bash`, `dash` or `zsh` with a flag holding `c` such as `-c` or `-lc`, of `python -c`, `node -e`, `php -r`, `perl -e` or `ruby -e`, and a heredoc or here-string fed to one of them. It reads workflow `run:` blocks, the YAML script keys (Ansible `shell:`, `command:`, `script:`, `raw:`, `cmd:` and `argv` lists in their `ansible.builtin.*` and `community.*` forms, compose `command:` and `entrypoint:`), shell scripts, Makefile recipes, Dockerfiles, Python `subprocess`, `os` and `asyncio` calls and JavaScript `execa` and `child_process` calls. The body of a shell, and a heredoc fed to no interpreter such as `RUN <<EOF`, is read once more, so each nesting level is a finding of its own. No comment can follow the opening quote of a body, so its nocheck may also stand alone on the line above the call. `clean.inline-script` measures the same YAML script keys and every Dockerfile RUN body against its limit of 11 logical lines.

## Repository bots

`rules/bots.yml` is the bot catalogue of [requirement 014](docs/requirements/repo/014-repository-bot-baseline.md): each bot's kind, whether it is free for public repositories with the source and the date that was checked, the evidence quality looks for, and where it is required. A bot that is not free for public repositories is never required on them; the catalogue refuses such an entry. Public repositories need every required bot; private ones need Dependabot and CODEOWNERS and get the other bots only by opt-in.

| Bot | Kind | Free for public (checked) | Required for | Evidence |
| --- | --- | --- | --- | --- |
| CodeRabbit | app | yes, [pricing](https://www.coderabbit.ai/pricing) (2026-11-28) | public | check run of `coderabbitai`, `.coderabbit.yaml` |
| Dependabot | native | yes, [docs](https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/about-dependabot-security-updates) (2026-11-28) | public and private | `.github/dependabot.yml`, alerts and security updates on |
| CODEOWNERS | file | yes, [docs](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners) (2026-11-28) | public and private | `.github/CODEOWNERS`, `CODEOWNERS` or `docs/CODEOWNERS` with a `*` owner |
| CodeQL | native | yes, [docs](https://docs.github.com/en/code-security/code-scanning/introduction-to-code-scanning/about-code-scanning-with-codeql) (2026-11-28) | public | check run `CodeQL` of `github-advanced-security` |
| OpenSSF Scorecard | file | yes, [scorecard-action](https://github.com/ossf/scorecard-action) (2026-11-28) | public | check run `Scorecard analysis` of `github-actions` |
| Greptile | app | no, [pricing](https://www.greptile.com/pricing) (2026-11-28) | opt-in | check run of `greptile-apps` |
| Strix | app | no, [repository](https://github.com/usestrix/strix) (2026-11-28) | opt-in | check run of `strix-security` |
| Vercel | app | no, [pricing](https://vercel.com/pricing) (2026-11-28) | opt-in | check run of `vercel` |

The bots apply only to a repository hosted on GitHub: without a remote on `github.com` (https, ssh or `git@github.com:` form) every `repo.bots.*` rule is `not_covered` and reports nothing.

- **Offline** (`quality check` in every mode): `repo.bots.missing-config` reports a missing bot file and a CODEOWNERS without a default owner, `repo.bots.config-drift` a `.coderabbit.yaml` or `.github/dependabot.yml` whose YAML differs from `quality export <coderabbit|dependabot>`. Both go through the differential gate, so a change is blamed only for what it adds. CodeRabbit's file depends on the visibility, so without `--github` it is reported as `not_covered`.
- **Export**: `quality export <coderabbit|dependabot>` prints the file, `--write` writes it at its path. The Dependabot file holds security updates only, grouped per ecosystem, weekly, for every ecosystem with a manifest, and grouped weekly version updates for `docker`, `docker-compose` and `github-actions`.
- **Online**: `quality check --all --github [--repo OWNER/NAME]` (or `--staged`, `--base REF`) reads `GITHUB_TOKEN` or `GH_TOKEN` and the repository from `--repo` or `GITHUB_REPOSITORY`. It reads the visibility, then `repo.bots.missing-evidence` reports a required bot without a check run on the newest pull request's head (Scorecard: on the default branch's head, since its workflow runs on push and schedule, never on pull requests) and `repo.bots.setting-off` each of Dependabot alerts, Dependabot security updates, secret scanning, push protection and private vulnerability reporting that is off. Without a token every online rule is `not_covered`, never a guess. The token needs read access; the two secret scanning states need admin rights and are `not_covered` without them. Dependabot alerts need Administration read access: a 403 leaves them `not_covered`, while GitHub's 404 for a token without access to the repository reads the same as alerts off.

`.quality/scanning.yml` is the one opt-out file, shared with requirement 013. Every entry needs a reason; an entry without one stops the check with exit 2. A tool switched off is reported as `not_covered`, not as a finding; `enabled: true` opts a private repository into an optional bot:

```yaml
tools:
  coderabbit: {enabled: false, reason: the code must not leave for third parties}
  greptile: {enabled: true, reason: accepted into the open-source programme}
paths:
  exclude: [vendor/]
```

`quality bots apply --repo OWNER/NAME` plans by default (`--dry-run`): it prints each API call, the config pull request and the operator steps, and writes nothing. `--apply` runs only those calls: it switches on the settings above and opens one pull request on `chore/quality-bot-baseline` with the exported files the default branch lacks or drifts from. It exits 1 while calls or operator steps remain. Run it as an operator row outside the sandbox, with a token that may administer the repository. What no API call can do comes out as an operator step:

- **App installation**: `install CodeRabbit: https://github.com/apps/coderabbitai/installations/new`; each install URL is the one `GET /apps/<slug>` returns, and an unknown slug stops the plan.
- **CodeQL and Scorecard**: the setup page of the bot, the repository's code security settings or the Scorecard workflow setup.
- **CODEOWNERS**: add the file with a default owner line; quality never generates it.

## Text presence tests

`test.text-presence` flags a test that reduces a source file to the presence of text, which core's `docs/contributing/actions/testing/regression.md` forbids: parse, render or run the file and assert on the result instead. It flags a test function (Python `test*`, a JavaScript or TypeScript `test` or `it` callback, PHP `test*` or `#[Test]`, Rust `#[test]`, Go `Test*(t *testing.T)`, Java `@Test`, Ruby `test_*` or an `it` block, a shunit2 `test*()` shell function) that reads a file, asserts at least once that the read text contains something, asserts nothing but containment, and neither parses, renders, writes nor runs anything. A test whose containment checks are all negative, such as a policy scan, stays clean, as does one on runtime output or on a fixture it writes itself. For Python the check is a builtin that follows the read text through assignments, slices, splits, regex extracts, comprehensions and line filters, through module constants, class attributes and `setUp`/`setUpClass`, and through helpers of the same file or of other modules of the repository it imports; a lint scan that collects the files missing a text and asserts the list empty counts as a positive check, one that collects the files holding a text as a negative one, also where it first narrows the scan to the files holding a scope text. What production code returns stays clean unless its name says it reads, and a lexer or address parse counts as running code, as does a test helper named for evaluating a condition or an order, such as `holds` or `*_precedes_*`. A YAML, JSON or TOML parse counts only where the condition that produces a finding uses the structure itself, a key, a type, a count bound or a leaf's equality with a value; a containment, regex, `startswith` or `endswith` on a string leaf of the parsed data is text presence, also where parsed structure merely selects or exempts files. A text read from one file and looked for in another is a cross-reference, and text the test plants into a read file, by `+`, `replace`, `re.sub`, a literal line beside it or a `copy.deepcopy` of parsed data, makes its check a different one, as does a comparison with a module of the code under test. The finding sits on the test's first line, so its nocheck goes there: `def test_x():  # nocheck: test.text-presence -- <reason>`.

## Version SPOT

`rules/spot.yml` keeps one source of truth per pinned version ([requirement 016](docs/requirements/rules/016-version-spot-drift.md)). Its pair catalogue, under `pairs` of `version.spot-drift`, names a source pin (an `npm` package in `package-lock.json` or `npm-shrinkwrap.json`, or a `pip` package pinned with `==` in a requirements file) and the copy of its version, such as `mcr.microsoft.com/playwright:v<version>` for `@playwright/test`; a pair without `name`, `source`, `ecosystem`, `package` or `copy`, or a copy without exactly one `<version>`, stops the check with exit 2. Where the snapshot pins a pair's source, `version.spot-drift` (medium) reports each copy in a build file (Makefile, Dockerfile, `*.env*` and `env.example`, compose, workflow, shell) whose version no source pin names, and `version.spot-literal` (medium) each copy spelled as a literal at all, since only a copy the build computes from the source, as a script that reads the lockfile does, follows a Dependabot bump. A change to a source file checks the copies of every build file, so a lockfile bump reports the copies it leaves behind; any other change checks the copies of the build files it touches. `version.duplicate-literal` (low) reports a version literal (`major.minor.patch`) of one name, such as `NODE_VERSION := 20.11.1` and `NODE_VERSION: 20.11.1`, that two or more build files spell, on the lines of the files the change touches; a workflow `uses:` line counts for none, since Dependabot bumps an action in every workflow at once, and changelogs, documentation, lockfiles and translations are no build files and stay out.

## Hosted scan

The role `web-app-cst-quality-check` serves the scan as a web page ([requirement 002](docs/requirements/scan/002-hosted-quality-scan.md)).

| Command | What it does |
| --- | --- |
| `make up` | Builds the images and serves the page at <http://localhost:18098/>, or on the port `QUALITY_DEV_PORT` names; `make down` removes the stack and its volumes. Needs a vulnerability bundle at `$QUALITY_DEV_DB/bundle` (default `~/.cache/quality-check/dev-db/bundle`), created once with `quality db update --db <that path>`. An exported `INFINITO_CACHE_PACKAGE_URL` makes the Nix builds use that package cache's `raw-nixos-cache` repository. |
| `make test-service` | Unit tests of the web app and the launcher, in a virtual environment under `.venv/service`. |
| `make test-egress INFINITO_CORE_DIR=<core> EGRESS_RUNTIMES="<runtimes>"` | Egress tests against the stack of `make up`; the step flags run through that core checkout's container wrapper, and every launcher and test-proxy test runs once under each runtime of `EGRESS_RUNTIMES`, such as `"runc sysbox-runc"`, which `docker info` must offer. |
| `make verify-test INFINITO_CORE_DIR=<core>` | Pulls the role into a core checkout with custom-role support and runs core's full test suite, lints included. |
| `make verify-compose INFINITO_CORE_DIR=<core>` | Runs `verify-test` first, then deploys the role with Keycloak through that checkout and runs its Playwright spec. |
| `make verify-playwright INFINITO_CORE_DIR=<core>` | Pulls the role into that checkout again and reruns its Playwright spec against the stack `verify-compose` left running; the scans the deploy skips while the launcher timer is stopped run here. |
| `make test-live INFINITO_CORE_DIR=<core> QUALITY_LIVE_MEMBER=<user> QUALITY_LIVE_MEMBER_PASSWORD_FILE=<file>` | Live tests against the stack `verify-compose` deployed in that checkout: socket, fetch network, state mount, upload limits, rate limits, realm sign-in. |

## Distribution

| Command | What it does |
| --- | --- |
| `make test-distribution` | Builds `packages.default` and `packages.image`, then checks pins, notices, `quality doctor` and the image. |
| `make test-e2e QUALITY_E2E_SKILLS=<repo> QUALITY_E2E_PACKAGE_MANAGER=<repo> QUALITY_E2E_RUNTIME=<runtime>` | Builds both outputs and checks that the host binary and the image, run under that Docker runtime (core's `SANDBOX_RUNTIME`, such as `runsc`), print the same `quality doctor` output and report the same findings on both repositories; needs Docker and the test bundle `make test-integration` fetches. |

## Benchmarks

The speed criteria of [requirement 001](docs/requirements/scan/001-language-agnostic-quality-check.md) and its recall bound on core run apart from `test-unit` and `test-integration`. The core checkout is only read.

| Command | What it does |
| --- | --- |
| `make test-bench QUALITY_CORE_DIR=<core> QUALITY_DB_DIR=<db>` | Times `quality --version` of the built `packages.default` against 0.15 s as the median of 9 runs and its `quality check --all` on core, deep tier included, against 360 s on 20 CPUs, both timings skipped with the measured load as the reason when 50 % or more of the CPUs are busy in the 5 s before or after them, and checks that `clean.default-value` finds every shell, Python and JavaScript default of `tests/bench/default-value-hits.json`, the hits of `defaults.py` of the kvb-code-clean skill on the core commit named there, which `QUALITY_CORE_DIR` must hold. Needs `nix build .#default` of this tree and a fresh bundle of `quality db update`. |

## Author
Kevin Veen-Birkenbach <kevin@veen.world>
