Pre-commit Hook¶
Catch agent card issues before they reach your repository.
Problem¶
You want to:
- Prevent invalid agent cards from being committed
- Get instant feedback during development
- Enforce standards without manual checks
- Share validation rules with the team
Solution: pre-commit Framework¶
1. Install pre-commit¶
2. Create Configuration¶
.pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: validate-agent-card
name: Validate Agent Card
entry: capiscio validate
language: system
files: agent-card\.json$
pass_filenames: true
3. Install the Hook¶
4. Test It¶
# Make a change to agent-card.json
echo '{}' > agent-card.json
git add agent-card.json
git commit -m "test"
# Hook will fail with validation errors!
Configuration Options¶
Basic Validation¶
.pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: validate-agent-card
name: Validate Agent Card
entry: capiscio validate
language: system
files: agent-card\.json$
pass_filenames: true
Strict Validation¶
.pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: validate-agent-card-strict
name: Validate Agent Card (Strict)
entry: capiscio validate --strict
language: system
files: agent-card\.json$
pass_filenames: true
Schema-Only (Fast)¶
.pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: validate-agent-card
name: Validate Agent Card Schema
entry: capiscio validate --schema-only
language: system
files: agent-card\.json$
pass_filenames: true
Multiple Agent Cards¶
For monorepos with multiple agents:
.pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: validate-agent-cards
name: Validate All Agent Cards
entry: capiscio validate
language: system
files: (agent-card\.json|agent-card\..+\.json)$
pass_filenames: true
This matches: - agent-card.json - agent-card.staging.json - agent-card.production.json - apps/foo/agent-card.json
Using Node CLI¶
If you prefer the Node.js CLI:
.pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: validate-agent-card
name: Validate Agent Card
entry: npx capiscio validate
language: system
files: agent-card\.json$
pass_filenames: true
Husky Alternative (Node.js Projects)¶
For npm/yarn projects, use Husky:
1. Install Husky¶
2. Add Hook¶
.husky/pre-commit
#!/bin/sh
# Find and validate all agent cards
for card in $(git diff --cached --name-only | grep 'agent-card.*\.json$'); do
echo "Validating: $card"
npx capiscio validate "$card" || exit 1
done
3. Make Executable¶
lint-staged Alternative¶
For more granular control with lint-staged:
.pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: lint-staged
name: lint-staged
entry: npx lint-staged
language: system
pass_filenames: false
Skip Hook When Needed¶
Sometimes you need to commit despite validation errors:
# Skip all hooks
git commit --no-verify -m "WIP: fixing agent card"
# Skip specific hook (pre-commit framework)
SKIP=validate-agent-card git commit -m "WIP"
Team Setup¶
Add instructions to your README:
README.md
## Development Setup
1. Install pre-commit:
```bash
pip install pre-commit
```
2. Install hooks:
```bash
pre-commit install
```
Agent card validation runs automatically on every commit.
CI Backup¶
Pre-commit hooks can be skipped. Add CI validation as a safety net:
.github/workflows/validate.yml
name: Validate
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate Agent Card
uses: capiscio/validate-a2a@v1
with:
agent-card: './agent-card.json'
Common Issues¶
Hook not running?
Make sure hooks are installed:
Verify the config:
Wrong file matched?
Test your regex pattern:
See Also¶
- CI/CD Quickstart — Full CI setup
- Schema-Only Mode — Fast validation
- Strict Mode — Production standards