Skip to content

AFS-Agentics/hookguard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hookguard

hookguard

Manage, validate, and enforce git hooks with conventional commit validation.

hookguard automates the setup and enforcement of consistent git workflows across teams. It installs git hooks (pre-commit, commit-msg), validates commit messages against the Conventional Commits spec, and runs configurable linting/formatters on staged files.

Features

  • Hook Installation — Install pre-commit and commit-msg hooks into any git repo
  • Commit Message Validation — Enforce Conventional Commits format: type(scope)!: description
  • Pre-commit Checks — Run configured linters/formatters on staged files
  • YAML Configuration — Define checks, allowed types, and rules in .hookguard.yml
  • Dry-run Mode — Preview changes without making them
  • Color Output — Auto-detects TTY vs piped output
  • macOS Compatible — Works with bash 3.2.57, no GNU-only flags
  • No Dependencies — Uses only standard macOS tools (bash, git, grep, sed, awk)

Installation

Option 1: Add to PATH

export PATH="$HOME/.hermes/profiles/mahnoor/data/agents/asad/projects/hookguard/bin:$PATH"

Option 2: Symlink

ln -s ~/.hermes/profiles/mahnoor/data/agents/asad/projects/hookguard/bin/hookguard /usr/local/bin/hookguard

Option 3: Makefile

cd ~/.hermes/profiles/mahnoor/data/agents/asad/projects/hookguard
make install

Usage

Initialize hooks in a repo

cd your-project
hookguard init          # First time
hookguard init --force  # Overwrite existing hooks

This installs pre-commit and commit-msg hooks into .git/hooks/ and generates a default .hookguard.yml config if none exists.

Uninstall hooks

hookguard uninstall

Removes hookguard-managed git hooks from the current repository. Only hooks that contain "hookguard" in their content are removed.

Validate a commit message

# Via argument
hookguard validate --message "feat(auth): add OAuth2 login"

# Via stdin
echo "fix(api): handle timeout" | hookguard validate

# Via commit message file (as a commit-msg hook would)
hookguard validate < .git/COMMIT_EDITMSG

Run pre-commit checks

# On staged files only
hookguard check --staged

# On all tracked files
hookguard check

Manage config

hookguard config              # Show current config
hookguard config --validate   # Validate config file

List commit types

hookguard list-types

Help and version

hookguard --help
hookguard --version

Configuration

Create a .hookguard.yml file in your project root:

# .hookguard.yml
version: 1
hooks:
  pre-commit:
    checks:
      - name: trailing-whitespace
        command: "grep -rnI '[[:space:]]$'"
        patterns: ["*.sh", "*.py", "*.js", "*.ts", "*.md"]
      - name: merge-conflict-markers
        command: "grep -rnI -E '<<<<<<<|=======|>>>>>>>'"
        patterns: ["*"]
  commit-msg:
    allowed_types: [feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert]
    require_scope: false
    max_subject_length: 72

Config Reference

Field Description Default
version Config schema version 1
hooks.pre-commit.checks List of check definitions See default
hooks.commit-msg.allowed_types Allowed conventional commit types feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
hooks.commit-msg.require_scope Whether scope is mandatory false
hooks.commit-msg.max_subject_length Max subject line length 72

Check Definition

Each check has:

  • name — Display name for the check
  • command — Shell command to run (receives matched files as arguments)
  • patterns — File glob patterns to match against

Conventional Commits Format

type(scope)!: description
  • type — One of: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
  • scope (optional) — A noun describing the section of codebase (e.g., auth, api, core)
  • ! (optional) — Indicates a breaking change
  • description — A short description of the change

Examples

feat(auth): add OAuth2 login flow
fix(api)!: remove deprecated v1 endpoint
docs: update API references
refactor(core): extract validation logic
test: add unit tests for auth module

Exit Codes

Code Meaning
0 Success
1 General error
2 Validation failure
3 Config error

Testing

The test suite uses BATS (available at /opt/homebrew/bin/bats).

# Run all tests
cd ~/.hermes/profiles/mahnoor/data/agents/asad/projects/hookguard
make test

# Or directly with bats
/opt/homebrew/bin/bats tests/

# Run a specific test file
/opt/homebrew/bin/bats tests/test_validate.bats

Project Structure

hookguard/
├── bin/
│   └── hookguard          # Main entry point (executable)
├── lib/
│   ├── utils.sh           # Shared utilities (logging, YAML parsing, dry-run)
│   ├── config.sh          # Config loading, validation, generation
│   ├── validate.sh        # Commit message validation
│   ├── hooks.sh           # Hook installation/uninstallation
│   └── checks.sh          # Pre-commit check execution
├── tests/
│   ├── helpers.bash       # Shared test helpers
│   ├── test_validate.bats # Commit message validation tests
│   ├── test_init.bats     # Hook installation tests
│   ├── test_check.bats    # Pre-commit checks tests
│   └── test_config.bats   # Config tests
├── .hookguard.yml         # Default configuration
├── Makefile               # Build/test/install automation
├── README.md              # This file
└── VERSION                # Version file

Development

Prerequisites

  • bash 3.2+ (macOS ships with 3.2.57)
  • git
  • BATS for testing (brew install bats-core)

Writing checks

Check commands should follow the convention:

  • Exit code 0 = check passed (no issues found)
  • Non-zero exit = check failed (issues found)
  • Output = details of what was found

License

MIT License

Copyright (c) 2026 AFS Agentics

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Manage, validate, and enforce git hooks with conventional commit validation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors