agentleFS
TsukiNi22TsukiNi22/ai-utils/skills/git/pre-commit/SKILL.md

pre-commit

Skill1 starsChanged 3 days agoMITView on GitHub

Set up the xstyle pre-commit hook of a git repository in Tsukini's way - checks the style of what is committed with xstyle (only the staged lines by default), refuses the commit on a major / unforgivable issue, warns on minor ones, only warns when xstyle is not installed - every option asked first with several choices (scope, fail / warn levels, safe auto fixes, missing xstyle, output, languages / excludes / ignored rules, local or shared .githooks), the needed tools checked and installed on request (xstyle, cmake, clang++, libutils), an existing hook kept and chained, and a throwaway demo repository to try it. Use whenever the user wants a pre-commit hook, a git hook checking the style, to block commits with style errors, or to change / remove that hook.

  • Pipes a download into a shell

12 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 12 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Ask all of them, even when a default exists (only skip what the request already says).

    line 42

“Common” is measured: kept by at least 6 in 10 of the 12 edited versions of this file we could read. “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

xstyle pre-commit hook

SKILL_DIR = the directory of this file.

  • templates/pre-commit: the hook (bash, config block at the top, readable by the user).
  • scripts/install_hook.sh install|remove|status [options] (--help), also curl -fsSL https://raw.githubusercontent.com/TsukiNi22/ai-utils/main/setup.sh | bash -s -- hook [command] [options] run from the repository.
  • scripts/demo_repo.sh [dir] [options]: throwaway repository (/tmp/xstyle-hook-demo) with one file per verdict and TRY.md listing the scenarios.

The hook runs locally at each git commit (before the commit exists), never on GitHub: the remote check is the style job of ci-cd (templates/style.yml). Both are complementary (local = fast feedback, skippable; CI = enforced).

Behavior (defaults)

CaseResult
xstyle not installedwarning xstyle not found, commit accepted (--missing warn)
unforgivable / major issueissues listed, commit refused (--fail-on major)
minor issue onlyissues listed + warning, commit accepted (--warn-on minor)
negligible only / cleansilent, commit accepted
mandatory rule (R34)never counted: neither refuses nor warns; shown with the issues when xstyle prints them (--r34 / XSTYLE_R34=1 or --extra "--r34" hides it)
xstyle crasheswarning, commit accepted (never blocks on a tool error)
Skip once: git commit --no-verify or XSTYLE_HOOK=0 git commit .... Fix: xstyle --fix --staged then git add -u.
Output: human (colors, source) in a terminal, --rtk automatically under Claude Code (CLAUDECODE) or XSTYLE_RTK=1.

1. Check the context (in parallel)

  • git rev-parse --show-toplevel (not a repository: propose git init), an existing hook (install_hook.sh status), git config core.hooksPath, a .pre-commit-config.yaml (framework pre-commit: propose a local hook xstyle --staged --fail-on major in it instead, ask).
  • Tools: command -v xstyle (xstyle --version), else what building it needs: cmake, clang++, libutils (pkg-config --exists utils or /usr/local/include/utils).
  • Languages of the repository (git ls-files | sed 's/.*\.//' | sort | uniq -c | sort -rn | head) and the build / generated / vendored folders (build, _deps, third_party...) to propose in the questions.

2. Ask every option (AskUserQuestion, French, recommended first)

Ask all of them, even when a default exists (only skip what the request already says). Two calls of up to 4 questions:

Call 1

  • Bloquer le commit à partir de (--fail-on): major (Recommandé: major + unforgivable) · unforgivable seulement · minor (strict) · jamais (avertir seulement).
  • Avertir à partir de (--warn-on): minor (Recommandé) · negligible (tout) · aucun avertissement.
  • Portée (--scope): Lignes indexées seulement (Recommandé: n'impose pas de corriger le code existant) · Fichiers indexés entiers · Tout le projet (lent).
  • xstyle absent (--missing): Avertir et laisser passer (Recommandé) · Refuser le commit · Ignorer en silence.

Call 2

  • Corrections automatiques (--fix): Non, seulement signaler (Recommandé) · Oui, les corrections sûres des fichiers entièrement indexés (ré-ajoutés au commit).
  • Installation (--shared / --link): Locale à ce clone (.git/hooks, Recommandé) · Partagée et versionnée (.githooks + core.hooksPath, toute l'équipe) · Lien vers le template (suit les mises à jour des skills).
  • Filtres (multiSelect, --extra): Exclure les dossiers générés (<the folders found>) · Seulement <top languages> · Ignorer des règles (lesquelles ?) · Aucun.
  • Sortie (--output): Auto (Recommandé: lisible au terminal, compacte sous Claude Code) · Toujours lisible · Toujours compacte (--rtk). Then, when xstyle is missing (only if): Installer xstyle ? Oui, via my-universe (Recommandé) (curl -fsSL https://tsukini22.github.io/my-universe/install.sh | bash -s then sudo dnf|apt|pacman install xstyle (packages of my-universe, sources: TsukiNi22/xstyle; no curl: wget -qO- instead of curl -fsSL)) · Non, le hook avertira seulement; libutils missing for the build: the libutils-install skill (ask first), cmake / clang++ missing: give the dnf / apt command (root through SUDO_ASKPASS=~/.local/bin/sudo-askpass sudo -A, ask). Last: Dépôt de démonstration ? Oui, /tmp/xstyle-hook-demo pour essayer · Non.

3. Install

bash SKILL_DIR/scripts/install_hook.sh install --repo <root> --fail-on major --warn-on minor --scope staged \
    --missing warn --fix none --output auto [--extra "-e build,_deps -l cpp,py -i CPP-AUTO"] [--shared | --link]
  • A hook already there (not xstyle's) is kept as pre-commit.local and run first (--force drops it: ask).
  • A reinstall starts from the defaults + the given options (the config block is rewritten); --link keeps the template as is (no option).
  • --shared: commit .githooks/ (with git-conventions, only if the user asks for the commit) and tell the team command git config core.hooksPath .githooks.
  • Demo: bash SKILL_DIR/scripts/demo_repo.sh /tmp/xstyle-hook-demo <same options>, then point to its TRY.md.

4. Verify and report

install_hook.sh status --repo <root> (config shown), then one real run without committing: git stash -k is never used; run the hook directly: .git/hooks/pre-commit; echo $? (it checks the staged lines; with nothing staged it exits 0). Report: where the hook is, the chosen options, what is refused / warned, how to skip it, how to change it (curl -fsSL https://raw.githubusercontent.com/TsukiNi22/ai-utils/main/setup.sh | bash -s -- hook --fail-on minor) or remove it (... | bash -s -- hook remove): the commands given to the user always use the remote form (the user may not have the ai-utils repository locally), with the download tool of the machine: curl -fsSL <url> | bash -s -- ..., else wget -qO- <url> | ..., else python3 -c 'import sys, urllib.request; sys.stdout.buffer.write(urllib.request.urlopen(sys.argv[1]).read())' <url> | ..., else the curl form (command -v curl wget python3); the scripts of this skill already print it that way.

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.