agentleFS
AmitSinghOMAmitSinghOM/agent-skills/skills/code-quality-gate/SKILL.md

code-quality-gate

Skill0 starsChanged 2 months agoMITView on GitHub

Use when preparing a pull request and you want a quality read on the diff, wiring a pre-commit hook or CI step that must fail only on NEW issues, triaging analyzer JSON/SARIF findings, or the user mentions code quality, complexity, changed-line gating, baselines, or SARIF. Runs the privacy-first offline analyzer cqa-analyzer (Python, Go, TypeScript/JS, Java, Kotlin, C#, C/C++, and an experimental Rust pilot) and turns findings into a deterministic pass/fail gate scoped to the lines you changed.

  • Installs packages

2 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions2 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 2

    1. kinhluan/skills★ 6same name
    2. pesap/skills★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository4 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 28
  2. Distinctive:

    Do not use it for runtime profiling or security-vulnerability scanning — it is a static quality gate, not a SAST or APM tool.

    line 35
  3. Very specific:

    Analysis health: Every run reports what it could and could not analyze (analysis_health in JSON).

    line 58
  4. Very specific:

    GitHub Actions: run with --format sarif > results.sarif and upload with github/codeql-action/upload-sarif so findings annotate the changed …

    line 121

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Quality Gate

Overview

Wraps cqa-analyzer — an offline static analyzer where no source leaves the machine — and converts its findings into one decision: did this diff introduce new issues on the lines it touched? Built for the pre-PR moment and for CI, where you need a deterministic yes/no plus a short, actionable finding list, not a wall of JSON.

The analyzer deliberately never invokes git, so it cannot know what changed. This skill supplies the missing piece: scripts/changed_lines_manifest.py turns a git diff into the changed-lines manifest the analyzer accepts, and scripts/run-gate.sh drives the whole flow with the correct flags.

Usage

Use this skill when:

  • Preparing a PR and you want a quality read on the diff before reviewers see it.
  • Wiring a pre-commit hook or a CI step that must fail the build only on new issues.
  • The analyzer emitted JSON/SARIF and you need it triaged into "must-fix vs. accept".
  • The user mentions code quality, cyclomatic complexity, changed-line gating, baselines, or SARIF.

Do not use it for runtime profiling or security-vulnerability scanning — it is a static quality gate, not a SAST or APM tool.

Core Concepts

  • Changed-line gate. Findings are intersected with the lines the diff touched. A pre-existing issue on an untouched line does not fail the gate; a new one does. This is what makes it safe to drop into CI on a legacy repository.
  • Baseline + new-findings-only. On a legacy repo, record today's findings once (--write-baseline), then gate only findings absent from that baseline. The analyzer hashes fingerprints, so the baseline contains no source text.
  • Offline and deterministic. Same input → same output, no network. The wrapper always passes --offline, which makes the analyzer deny socket operations while it runs. A green local run predicts a green CI run.
  • Two machine formats. json for caches and dashboards, sarif (2.1.0) for code-host annotations on the changed lines. text for humans.
  • Configuration is pinned outside the tree being gated. A pull request could otherwise edit .code-quality.toml to disable a rule or exclude a path and pass the gate. --config <file> (use a file the PR cannot touch), --no-project-config (defaults only), or --expect-config-fingerprint <sha256> (analyzer exits 6 before scanning if the effective config differs) close that hole. Read the fingerprint once from configuration_fingerprint in a trusted JSON run and commit it to CI config.
  • Analysis health. Every run reports what it could and could not analyze (analysis_health in JSON). Zero findings with parse failures means the scan was blind, not clean — --strict turns that into a non-zero exit.

Quick Reference

pipx install cqa-analyzer            # or: pip install cqa-analyzer

# One-time on a legacy repo: record the accepted floor (no gate)
scripts/run-gate.sh --write-baseline .code-quality-baseline.json

# Gate a branch: only NEW warning+ findings on CHANGED lines can fail (exit 4)
scripts/run-gate.sh --base origin/main --baseline .code-quality-baseline.json --format sarif > results.sarif

# Pre-commit: gate the lines you are about to commit
scripts/run-gate.sh --staged --baseline .code-quality-baseline.json

# Clean repo (no legacy debt): gate every changed-line finding, be strict about scan health
scripts/run-gate.sh --base origin/main --strict

# CI-hardened: the PR cannot weaken the gate by editing the repo's own config
scripts/run-gate.sh --base origin/main --baseline .code-quality-baseline.json \
  --expect-config-fingerprint "$CQA_CONFIG_FINGERPRINT" --strict --format sarif > results.sarif
Wrapper flagAnalyzer flags it drivesMeaning
--base <ref>--changed-lines-manifest (generated from git diff <ref>...HEAD)Gate only lines changed since the merge-base
--staged--changed-lines-manifest (from git diff --cached)Gate staged lines (pre-commit)
--baseline <file>--baseline <file> --new-findings-onlyIgnore findings already in the accepted floor
--write-baseline <file>--write-baseline <file>Record the floor; no gate
--format json|sarif|text--output-formatMachine cache / code-host annotations / human
--fail-on warning|error--fail-onSeverity that fails the gate (default warning)
--strict--strictNon-zero exit if any requested analysis could not run
--config <file>--configUse this config; ignore the repo's .code-quality.toml
--no-project-config--no-project-configAnalyzer defaults only
--expect-config-fingerprint <sha256>--expect-config-fingerprintExit 6 before scanning if the effective config differs
--report-only(drops --fail-on)Always exit 0. Prints a loud warning.
CQA_CMD=/abs/path—Pin the analyzer binary; must be absolute (PATH-hijack guard)

Exit codes: 0 clean · 4 gate failed · 6 config fingerprint mismatch (both the analyzer's own) · 2 usage error · 3 environment error (missing analyzer, missing baseline) from the wrapper. --report-only remaps only 4; a 6 still fails.

Pre-PR Gate Checklist

Gate Progress:
- [ ] cqa-analyzer installed (or CQA_CMD set to an absolute path)
- [ ] Baseline exists (legacy repo) — or repo is clean and no baseline is needed
- [ ] In CI: config pinned (--expect-config-fingerprint or --config outside the tree)
- [ ] Ran: scripts/run-gate.sh --base origin/main [--baseline ...]
- [ ] analysis_health shows 0 parse failures (else the result is not trustworthy)
- [ ] Reviewed must-fix findings on changed lines
- [ ] SARIF uploaded if annotating the PR

Integration Patterns

  • Pre-commit: a .pre-commit-hooks.yaml entry calling scripts/run-gate.sh --staged --baseline .code-quality-baseline.json blocks the commit before it reaches a PR.
  • GitHub Actions: run with --format sarif > results.sarif and upload with github/codeql-action/upload-sarif so findings annotate the changed lines. Fetch enough history for the merge-base (fetch-depth: 0) and pin the config with --expect-config-fingerprint from a repository variable, so a PR cannot turn the gate off by editing .code-quality.toml.
  • Agent-driven PR prep: the agent runs the gate with --format json, reads the selected findings, and reports the must-fix list to the user before opening the PR.

See references/output-contracts.md for the JSON/SARIF field shapes and references/changed-lines-manifest.md for the manifest schema the generator emits.

Common Mistakes

  • With --report-only you MUST lead with the warning the wrapper prints: REPORT ONLY: this run exits 0 and will not block the build even when findings exist. Do not bury it in exit-code details.
  • You MUST NOT gate a legacy repo without a baseline, because the first CI run drowns in pre-existing findings and the team disables the gate. Write a baseline once, then gate with --baseline.
  • You MUST check analysis_health before trusting an empty result; zero findings with N parse failures means the scan was blind, not clean.
  • You MUST NOT feed JSON to a code host expecting inline annotations; hosts annotate from SARIF. JSON is for caches and dashboards.
  • You MUST NOT run an unpinned gate in CI on a repository where pull requests can edit .code-quality.toml; the gate is then advisory, not a gate.
  • You MUST NOT claim a scan ran if the analyzer was not found. The wrapper exits 3 with an install hint; relay that, never fabricate findings.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.