Hooks
Les hooks permettent d'exécuter des commandes automatiquement à des moments clés du pipeline ATOOX.
Types de hooks
Hooks Claude Code
Configurés dans settings.json de Claude Code.
{
"hooks": {
"PreToolUse": [],
"PostToolUse": [],
"PreEdit": [],
"PostEdit": []
}
}
Hooks ATOOX
Configurés dans .atooxrc.yml.
hooks:
pre_pipeline: []
post_pipeline: []
pre_step: []
post_step: []
on_error: []
Hooks Claude Code
PreToolUse
S'exécute AVANT qu'un outil soit utilisé.
{
"hooks": {
"PreToolUse": [
{
"matcher": "Edit|Write",
"command": "atoox validate --quick"
}
]
}
}
Use cases :
- Valider avant modification
- Bloquer certaines opérations
- Logger les actions
PostToolUse
S'exécute APRÈS qu'un outil soit utilisé.
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"command": "npm run lint --fix"
}
]
}
}
Use cases :
- Auto-fix après modification
- Mettre à jour des dépendances
- Notifier
Matchers
| Pattern | Correspond à |
|---|---|
Edit |
Modifications de fichiers |
Write |
Création de fichiers |
Edit\|Write |
L'un ou l'autre |
Bash |
Commandes shell |
* |
Tout |
Hooks ATOOX
pre_pipeline
S'exécute avant le démarrage du pipeline.
hooks:
pre_pipeline:
- command: git fetch origin
description: "Synchroniser avec origin"
- command: npm install
description: "Installer les dépendances"
condition: "package-lock.json changed"
post_pipeline
S'exécute après la fin du pipeline (succès ou échec).
hooks:
post_pipeline:
- command: npm run build
description: "Builder le projet"
on: success
- command: atoox report
description: "Générer le rapport"
on: always
pre_step
S'exécute avant chaque step.
hooks:
pre_step:
- step: execute
command: echo "Début de l'exécution"
- step: tests
command: docker-compose up -d
description: "Démarrer les services de test"
post_step
S'exécute après chaque step.
hooks:
post_step:
- step: validate
command: npm run format
description: "Formater le code"
- step: tests
command: docker-compose down
description: "Arrêter les services"
on_error
S'exécute quand une erreur survient.
hooks:
on_error:
- command: atoox notify --channel=slack "Pipeline failed"
description: "Notifier l'équipe"
- command: git stash
description: "Sauvegarder les changements"
Configuration avancée
Conditions
hooks:
pre_pipeline:
- command: npm install
condition: "file_changed:package.json"
- command: npm run migrations
condition: "file_changed:prisma/schema.prisma"
- command: docker-compose up -d
condition: "env:CI != true"
Conditions disponibles
| Condition | Description |
|---|---|
file_changed:path |
Fichier modifié |
file_exists:path |
Fichier existe |
branch:pattern |
Branche correspond au pattern |
env:VAR = value |
Variable d'environnement |
mode:name |
Mode actif |
always |
Toujours |
never |
Jamais |
Timeout
hooks:
pre_pipeline:
- command: npm test
timeout: 300000 # 5 minutes en ms
on_timeout: warn # warn | fail | ignore
Parallélisation
hooks:
pre_pipeline:
- parallel:
- command: npm run lint
- command: npm run typecheck
- command: npm run test:unit
description: "Validations en parallèle"
Exemples pratiques
Validation automatique
# .atooxrc.yml
hooks:
post_step:
- step: execute
commands:
- npm run lint --fix
- npm run format
- git add -A
description: "Auto-fix et stage"
Intégration Docker
hooks:
pre_pipeline:
- command: docker-compose -f docker-compose.test.yml up -d
description: "Démarrer l'environnement de test"
post_pipeline:
- command: docker-compose -f docker-compose.test.yml down
on: always
description: "Nettoyer l'environnement"
Notifications Slack
hooks:
post_pipeline:
- command: |
curl -X POST $SLACK_WEBHOOK \
-H 'Content-type: application/json' \
-d '{"text": "Pipeline terminé: ${ATOOX_FEATURE}"}'
on: success
description: "Notifier Slack"
Génération de documentation
hooks:
post_step:
- step: docs
command: npm run docs:build
description: "Générer la doc technique"
Déploiement preview
hooks:
post_pipeline:
- command: vercel deploy --preview
condition: "branch:feature/*"
on: success
description: "Déployer en preview"
Hooks Git natifs
ATOOX peut aussi configurer les hooks Git natifs.
git:
hooks:
pre_commit:
- npm run lint-staged
commit_msg:
- npx commitlint --edit $1
pre_push:
- npm test
- npm run build
Installation
# Installer les hooks Git
atoox hooks install
# Désinstaller
atoox hooks uninstall
# Lister les hooks actifs
atoox hooks list
Debugging
Mode verbose
ATOOX_HOOK_DEBUG=true atoox
Logs
output:
hooks:
log: true
log_file: .atoox/hooks.log
Tester un hook
atoox hook test pre_pipeline
atoox hook test post_step:validate
Bonnes pratiques
1. Hooks rapides
# ✅ Bon : hook rapide
hooks:
pre_step:
- step: execute
command: echo "Starting..."
# ❌ Mauvais : hook lent qui bloque
hooks:
pre_step:
- step: execute
command: npm run full-build # Trop long
2. Gestion des erreurs
hooks:
pre_pipeline:
- command: npm install
on_error: fail # fail | warn | ignore
retry: 2 # Nombre de tentatives
3. Isolation
hooks:
pre_pipeline:
- command: npm test
env:
NODE_ENV: test
CI: true
Prochaines étapes
- Configuration .atooxrc — Configuration complète
- CLI PRO — Hooks avancés
- Pipeline — Comprendre les steps