skills/quality-gate/SKILL.md
Use when: creating, auditing, or optimizing repository quality gates (git hooks, pre-commit checks, CI guards, merge protection)
npx skillsauth add ryderfreeman4logos/cli-sub-agent quality-gateInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Create, audit, and optimize multi-layer quality gates for any repository. Gates enforce code quality deterministically — through tooling, not instructions.
Layer 1: PRE-COMMIT (developer machine, every commit)
├── Branch protection (block commits to protected branches)
├── Monolith guard (block oversized files by token/line count)
├── Artifact guard (block generated/scratch files from staging)
├── Version guard (version must differ from base branch)
├── Charset guard (enforce codebase language consistency)
├── Format (auto-format + auto-stage formatted files)
├── Lint (language-specific strict linting)
├── Dependency audit (license + vulnerability scanning)
└── Test (unit + integration + e2e)
Layer 2: PRE-PUSH (before code reaches remote)
├── Version bump verification (redundant check, different timing)
├── Review verification (require recorded review session for HEAD)
└── Advisory warnings (e.g., missing PR-bot marker for open PRs)
Layer 3: PRE-MERGE (before merging to protected branch)
├── Review completion marker verification
├── CI status check (all checks green)
└── Merge command interception (PATH-injected wrapper)
Layer 4: POST-MERGE (after code lands on protected branch)
├── Auto-rebuild (recompile and install updated binaries)
├── Notification (audit log, team alerts)
└── Cleanup (stale branch pruning, marker cleanup)
Analyze the repository to determine:
Tech stack detection:
# Check for language indicators
ls Cargo.toml package.json go.mod pyproject.toml Makefile justfile \
CMakeLists.txt build.gradle pom.xml 2>/dev/null
Hook manager detection:
# Lefthook (preferred)
ls lefthook.yml lefthook.yaml .lefthook.yml 2>/dev/null
# Husky (Node.js)
ls .husky/_/husky.sh 2>/dev/null
# pre-commit (Python)
ls .pre-commit-config.yaml 2>/dev/null
# Raw git hooks
ls .git/hooks/pre-commit .git/hooks/pre-push 2>/dev/null
Task runner detection:
ls justfile Justfile Makefile makefile package.json 2>/dev/null
Existing gate inventory — enumerate all active checks:
Coverage gap analysis — compare against the 4-layer model above, report which gates exist and which are missing.
Output a structured audit report with coverage matrix:
GATE AUDIT REPORT
=================
Tech Stack: Rust (Cargo workspace)
Hook Manager: lefthook (v2.x)
Task Runner: just
Layer 1 (Pre-Commit):
[x] Branch protection
[x] Format (cargo fmt)
[x] Lint (clippy)
[x] Test
[ ] Monolith guard <- MISSING
[ ] Artifact guard <- MISSING
[ ] Dependency audit <- MISSING
Layer 2 (Pre-Push):
[ ] Version check <- MISSING
...
Based on the audit, design gates for each missing layer. Follow tech-stack-specific best practices:
| Stack | Format | Lint | Type Check | Test | Dep Audit | Monolith |
|-------|--------|------|------------|------|-----------|----------|
| Rust | cargo fmt | cargo clippy -- -D warnings | (compiler) | cargo nextest run | cargo deny check | tokuin/wc -l |
| Go | gofmt -l . | golangci-lint run | (compiler) | go test ./... | govulncheck ./... | tokuin/wc -l |
| Python | ruff format | ruff check | mypy --strict | pytest | pip-audit | tokuin/wc -l |
| TypeScript | biome format | biome check | tsc --noEmit | vitest run | npm audit | tokuin/wc -l |
| Mixed | Per-language | Per-language | Per-language | Per-language | Per-language | tokuin/wc -l |
For each missing gate, decide:
Generate the following files based on design decisions:
Preferred: lefthook (language-agnostic, fast, single binary).
# lefthook.yml
pre-commit:
commands:
branch-protection:
run: scripts/hooks/branch-protection.sh
quality-gates:
run: just pre-commit
pre-push:
commands:
version-check:
run: scripts/hooks/version-check.sh
# Add review-check if using csa:
# review-check:
# run: scripts/hooks/review-check.sh
post-merge:
commands:
rebuild:
run: scripts/hooks/post-merge-rebuild.sh
If the project already uses husky or pre-commit, adapt to that tool instead.
Organize recipes in this order:
1. default: pre-commit (run all checks)
2. Individual gates:
a. find-monolith-files (token/line count guard)
b. check-generated-artifacts (block generated files from staging)
c. check-version-bumped (version differs from base branch)
d. check-charset (enforce codebase language if needed)
e. fmt (format + auto-stage)
f. deny / audit (dependency audit)
g. lint / clippy (strict linting)
h. test (unit tests)
i. test-e2e (end-to-end tests)
3. pre-commit: a b c d e f g h i (orchestration recipe)
Critical patterns to include:
Monolith Guard — block oversized files that degrade LLM/reviewer performance:
# Token-count check (requires tokuin, falls back to line count)
# Thresholds: MONOLITH_TOKEN_THRESHOLD (default 8000), MONOLITH_LINE_THRESHOLD (default 800)
# Process: git ls-files | parallel check_file {}
# Exclusions: *.lock, generated docs, workflow definitions
# Output: actionable error with stash-then-split instructions
Artifact Guard — block generated/scratch files from being committed:
# Check git diff --cached --name-only --diff-filter=ACMR against patterns:
# .test-target/, .tmp/, target/, dist/, node_modules/, __pycache__/
# Allow DELETIONS (cleanup commits should work)
Version Guard — enforce version bump on feature branches:
# Compare current version vs base branch version
# Skip on main/dev, skip if CSA_SKIP_VERSION_CHECK=1
# Error message includes the bump command (just bump-patch / npm version patch / etc.)
Format + Auto-Stage — format and re-add only modified tracked files:
# Run formatter
# git diff --name-only | grep '<ext>' | xargs -r git add
# This allows fmt to be part of pre-commit without manual re-staging
Each hook script MUST follow this template:
#!/usr/bin/env bash
# <Purpose>: <one-line description>
set -euo pipefail
# ── Skip conditions ─────────────────────────────────────────────
# Skip inside sandbox/CI environments
if [ -n "${CSA_SESSION_ID:-}" ]; then
echo "[<hook>] Inside sandbox -- skipping."
exit 0
fi
# ── Main logic ──────────────────────────────────────────────────
# ...
# ── Error output ────────────────────────────────────────────────
# MUST include:
# 1. What failed (exact condition)
# 2. How to fix it (exact command)
# 3. Why it matters (one line)
Branch Protection (scripts/hooks/branch-protection.sh):
#!/usr/bin/env bash
set -euo pipefail
branch=$(git symbolic-ref --short HEAD 2>/dev/null) || exit 0
[ -z "$branch" ] && exit 0
PROTECTED="main dev master"
for pb in $PROTECTED; do
if [ "$branch" = "$pb" ]; then
echo "BLOCKED: Cannot commit directly to '$branch'."
echo "Create a feature branch: git checkout -b feat/<description>"
exit 1
fi
done
Post-Merge Rebuild (scripts/hooks/post-merge-rebuild.sh):
#!/usr/bin/env bash
# Skip sandbox, check writable target, rebuild
set -euo pipefail
if [ -n "${CSA_SESSION_ID:-}" ]; then exit 0; fi
if [ ! -w /usr/local/bin ]; then
echo "[post-merge] Install target not writable -- skipping."
exit 0
fi
echo "[post-merge] Rebuilding..."
if just install; then
echo "[post-merge] Installed successfully."
else
echo "[post-merge] WARNING: build failed (exit $?)." >&2
fi
.csa/review-checklist.md)Project-specific review items that encode hard-won lessons:
# Project Review Checklist
Common pitfalls and patterns to verify during code review:
- [ ] <Domain-specific check 1>
- [ ] <Domain-specific check 2>
...
Derive items from:
Add to justfile:
install-hooks:
@git config --unset core.hooksPath 2>/dev/null || true
lefthook install
@echo "Hooks installed."
just pre-commit on the current codebasejust pre-commit — should be < 60s for good DXCSA_SESSION_ID is settokuin estimate (fallback: wc -l).test-target/, .tmp/, target/, dist/, node_modules/, __pycache__/, *.pycCSA_SKIP_VERSION_CHECK=1rg "\p{Script=Han}" (or equivalent Unicode script check)git add modified tracked filescargo fmt, gofmt, ruff format, biome format, prettiercargo deny check, npm audit, pip-audit, govulncheck-D warnings)cargo clippy, golangci-lint run, ruff check, biome check, eslintcargo nextest run, go test, pytest, vitest runcsa session list --format json for review session matching branch + HEAD.done marker file for the PR + current HEAD SHA~/.local/state/cli-sub-agent/pr-bot-markers/{REPO}/{PR}-{SHA}.donegh pr merge to enforce review gateghcsa hooks install-merge-guard)CSA_SESSION_ID), read-only install target~/.local/state/cli-sub-agent/audit/merge-events.jsonl| Anti-Pattern | Why It's Wrong | Correct Approach |
|--------------|----------------|------------------|
| --no-verify / -n | Bypasses ALL hooks | Fix the failing check |
| LEFTHOOK=0 env var | Disables hook manager | Fix the failing check |
| git config core.hooksPath /dev/null | Redirects hooks to void | Use lefthook install |
| Catch-all \|\| true in gates | Swallows real failures | Only on skip conditions |
| Hard-coding paths in hooks | Breaks portability | Use git rev-parse --show-toplevel |
| Running slow tests in pre-commit | Ruins DX (> 60s) | Move to pre-push or CI |
| Advisory-only for critical gates | Gets ignored | Hard fail with clear error |
| Checking tool version in gate | Fragile, over-specified | Check behavior, not version |
| Command | Effect |
|---------|--------|
| /quality-gate | Full audit of current repository's gate infrastructure |
| /quality-gate audit | Audit-only (no changes) |
| /quality-gate create | Create gate infrastructure from scratch |
| /quality-gate optimize | Analyze and improve existing gates |
| /quality-gate add monolith-guard | Add specific gate to existing setup |
just pre-commit (or equivalent) exits 0 on current codebase.CSA_SESSION_ID is set.lefthook install (or equivalent) documented in setup recipe.development
Use when running a non-blocking CSA background code health scan that uses csa health and csa tokuin estimate to propose refactoring GitHub issues for files over token or complexity thresholds.
data-ai
Recover main-agent context after `/clear`, `/compact`, or lost local thread state by using `csa recall` against recorded Claude main sessions.
tools
Use when: merged PR had HIGH/CRITICAL findings that represent a bug class — extracts reusable coding rule
tools
Use when: review found 2+ independent findings in different files, fix phase can parallelize RECON