claude-git-hooks 2.7.1 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,169 @@ Todos los cambios notables en este proyecto se documentarán en este archivo.
5
5
  El formato está basado en [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  y este proyecto adhiere a [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.9.1] - 2025-12-30
9
+
10
+ ### 🐛 Fixed
11
+
12
+ - **Template path mismatch after v2.8.0 migration** - Fixed critical bug where templates were not found after config migration (#51)
13
+ - **What was broken**: After v2.8.0 moved templates from `.claude/` to `.claude/prompts/`, the code still looked in the old location
14
+ - **Root cause**: `prompt-builder.js` and `resolution-prompt.js` had hardcoded `.claude/` paths instead of `.claude/prompts/`
15
+ - **Symptom**: `ENOENT: no such file or directory` errors for `CLAUDE_ANALYSIS_PROMPT.md` and `CLAUDE_RESOLUTION_PROMPT.md`
16
+ - **Fix**: Updated default paths in template loading functions to `.claude/prompts/`
17
+ - **Files changed**:
18
+ - `lib/utils/prompt-builder.js:45,133,223,234-235,244` - Updated `loadTemplate`, `loadPrompt`, `buildAnalysisPrompt` defaults
19
+ - `lib/utils/resolution-prompt.js:183` - Updated `generateResolutionPrompt` template path
20
+ - **Impact**: Pre-commit analysis and resolution prompt generation now work correctly after v2.8.0+ installation
21
+
22
+ ### 🎯 User Experience
23
+
24
+ - **Before**: Users upgrading from v2.6.x to v2.8.0+ experienced "Template not found" errors even after successful installation
25
+ - **After**: Templates are found in correct `.claude/prompts/` directory as intended by v2.8.0 changes
26
+
27
+ ## [2.9.0] - 2025-12-26
28
+
29
+ ### ✨ Added
30
+
31
+ - **Local telemetry system with per-retry tracking** - Enabled by default for debugging JSON parsing failures (#50)
32
+ - **What it does**: Tracks JSON parsing failures and successes with full context, recording EVERY retry attempt individually
33
+ - **Key features**:
34
+ - **Granular tracking**: Records each retry attempt separately (not just final result)
35
+ - **Unique IDs**: Each event has unique ID (timestamp-counter-random) for deduplication
36
+ - **Success flag**: Boolean indicating whether attempt succeeded (true) or failed (false)
37
+ - **Retry metadata**: `retryAttempt` (0-3) and `totalRetries` (max configured)
38
+ - **Error types**: Tracks EXECUTION_ERROR, JSON_PARSE_ERROR, etc.
39
+ - **Hook coverage**: pre-commit, prepare-commit-msg, analyze-diff, create-pr
40
+ - **Privacy-first**: Local-only (`.claude/telemetry/`), no data leaves user's machine, no external transmission
41
+ - **Storage**: JSON lines format with automatic rotation (keeps last 30 days)
42
+ - **CLI commands**:
43
+ - `claude-hooks telemetry show` - Display statistics (failure rate, failures by batch size/model/hook, retry patterns)
44
+ - `claude-hooks telemetry clear` - Reset telemetry data
45
+ - **Enabled by default**: To disable, add `"system": { "telemetry": false }` to `.claude/config.json`
46
+ - **Files added**:
47
+ - `lib/utils/telemetry.js` - Telemetry collection with ID generation, retry tracking, and statistics
48
+ - **Files changed**:
49
+ - `lib/utils/claude-client.js:678-780,788-798` - Modified withRetry() to record telemetry on each attempt
50
+ - `lib/utils/claude-client.js:609-618,845-856` - Removed duplicate telemetry recordings
51
+ - `lib/hooks/pre-commit.js` - Pass telemetry context for analysis
52
+ - `lib/hooks/prepare-commit-msg.js` - Pass telemetry context for commit messages
53
+ - `lib/config.js` - Add telemetry config option (default: true)
54
+ - `bin/claude-hooks:1076-1091,1354-1366` - Add telemetry context to analyze-diff and create-pr
55
+ - `bin/claude-hooks` - Add telemetry CLI commands
56
+ - **Impact**: Enables diagnosis of retry patterns, identifies which retry attempts succeed, tracks transient vs persistent errors, helps optimize batch sizes and models
57
+
58
+ ## [2.8.0] - 2025-12-24
59
+
60
+ ### 🎨 Changed
61
+
62
+ - **Simplified configuration format** - New v2.8.0 config structure reduces redundancy and improves maintainability
63
+ - **What changed**: Config now uses `version` field and `overrides` structure, 21 parameters moved to hardcoded defaults
64
+ - **New format**: `{ "version": "2.8.0", "preset": "backend", "overrides": {...} }`
65
+ - **Old format**: `{ "preset": "backend", "analysis": {...}, "subagents": {...}, ... }` (20+ top-level keys)
66
+ - **User-configurable** (5 params): `preset`, `github.pr.*`, `subagents.batchSize`
67
+ - **Hardcoded** (21 params): `analysis.*` (maxFileSize, maxFiles, timeout), `commitMessage.*`, `templates.*`, etc.
68
+ - **Advanced** (3 params): `analysis.ignoreExtensions`, `commitMessage.taskIdPattern`, `subagents.model`
69
+ - **Files changed**:
70
+ - `lib/config.js:1-280` - Split into HARDCODED and defaults, added legacy format detection
71
+ - `templates/config.example.json` - New simplified format with examples
72
+ - `templates/config.advanced.example.json` - Advanced parameters with documentation
73
+ - `bin/claude-hooks:483-570` - Auto-migration during install
74
+ - **Impact**: Cleaner config files, sensible defaults work for 99% of users
75
+
76
+ - **Automatic config migration** - Legacy configs auto-migrate during installation with backup
77
+ - **What changed**: `claude-hooks install` detects legacy format and migrates automatically
78
+ - **Migration process**: Backup to `.claude/config_old/`, extract allowed params, create v2.8.0 config
79
+ - **Preserved settings**: `github.pr.*`, `subagents.batchSize`, and advanced params (with warnings)
80
+ - **Files changed**:
81
+ - `bin/claude-hooks:510-530,1942-2115` - Auto-migration in install, new `migrate-config` command
82
+ - **Impact**: Seamless upgrade path, settings preserved, zero manual work
83
+
84
+ - **Organized prompt templates** - All .md files moved to `.claude/prompts/` subdirectory
85
+ - **What changed**: Installation creates `.claude/prompts/` and places markdown templates there
86
+ - **Old location**: `.claude/CLAUDE_ANALYSIS_PROMPT.md`, `.claude/CLAUDE_PRE_COMMIT.md`, etc.
87
+ - **New location**: `.claude/prompts/CLAUDE_ANALYSIS_PROMPT.md`, `.claude/prompts/CLAUDE_PRE_COMMIT.md`, etc.
88
+ - **Auto-cleanup**: Old .md files in `.claude/` root are automatically removed during installation
89
+ - **Files changed**:
90
+ - `bin/claude-hooks:401-457` - Creates prompts directory, moves .md files, cleans up old files
91
+ - `lib/config.js:57` - Updated `templates.baseDir` to `.claude/prompts`
92
+ - **Impact**: Cleaner `.claude/` directory structure, prompts separated from config files
93
+
94
+ - **Parallel analysis enabled by default** - Subagents now hardcoded to enabled (was opt-in)
95
+ - **What changed**: `subagents.enabled` moved from user config to hardcoded `true`
96
+ - **Why**: Faster analysis is universally beneficial, no reason to disable
97
+ - **Files changed**: `lib/config.js:52-54` - Hardcoded `enabled: true`, `model: 'haiku'`, `batchSize: 3`
98
+ - **Impact**: All users get faster analysis out-of-box (4x speedup on 3+ files)
99
+
100
+ ### ✨ Added
101
+
102
+ - **Config example files** - Split documentation into simple and advanced examples
103
+ - `templates/config.example.json` - Minimal config (99% of users) with inline examples
104
+ - `templates/config.advanced.example.json` - Advanced parameters with full documentation
105
+ - Installation copies both to `.claude/config_example/` for reference
106
+ - **Impact**: Clear guidance for common use cases, power users can tinker safely
107
+
108
+ - **Manual config migration command** - New `claude-hooks migrate-config` for manual upgrades
109
+ - Checks config version, creates backup in `.claude/config_old/`
110
+ - Extracts allowed parameters, warns about advanced params
111
+ - Shows diff preview before writing
112
+ - **Impact**: Users can migrate at their pace, review changes before applying
113
+
114
+ ### 🔧 Fixed
115
+
116
+ - **Preset name now correctly displayed in hooks** - Fixed config loader not including preset name in final config
117
+ - **What was broken**: Hooks always showed "Default (General-purpose)" preset regardless of actual preset configured
118
+ - **Root cause**: Config loader extracted `presetName` but never added it to the final merged config object
119
+ - **Fix**: Add `preset` field to final config object after merge operations
120
+ - **Files changed**: `lib/config.js:181-184`
121
+ - **Impact**: Hooks now correctly display configured preset (e.g., "AI", "Backend", "Frontend")
122
+
123
+ - **Example configs no longer clutter .claude/** - Example files only exist in `.claude/config_example/`
124
+ - **What was broken**: Installation copied `*example.json` to both `.claude/` and `.claude/config_example/`
125
+ - **Fix**: Filter `*example.json` during template copy, only place in `config_example/`
126
+ - **Files changed**: `bin/claude-hooks:410-415,498-507`
127
+ - **Impact**: Cleaner `.claude/` directory without redundant example files
128
+
129
+ ### ⚠️ Breaking Changes
130
+
131
+ - **Config format change** - Legacy config format (pre-v2.8.0) requires migration
132
+ - **Migration**: Automatic during `install`, or manual via `claude-hooks migrate-config`
133
+ - **Compatibility**: Legacy format still works with deprecation warning until v3.0.0
134
+ - **Action required**: None (auto-migrates), but consider running `migrate-config` to see diff
135
+
136
+ - **Template location change** - .md files moved from `.claude/` to `.claude/prompts/`
137
+ - **Migration**: Automatic during `install --force`
138
+ - **Custom templates**: If you customized templates, move them to `.claude/prompts/` manually
139
+ - **Impact**: Low - most users don't customize, system checks both locations
140
+
141
+ - **Hardcoded parameters** - 21 parameters no longer user-configurable in .claude/config.json
142
+ - **Removed from user config**: `analysis.*` (except ignoreExtensions), `commitMessage.*` (except taskIdPattern), `templates.*`, `output.*`, `system.*`, `git.*`, `subagents.enabled`, `subagents.model` (except in advanced config)
143
+ - **Rationale**: Sensible defaults work for everyone, reduces configuration complexity
144
+ - **Override**: Advanced params available in `config.advanced.example.json` (use with caution)
145
+
146
+ ## [2.7.2] - 2025-12-23
147
+
148
+ ### ✨ Added
149
+
150
+ - **Retry logic for PR commands** - Added automatic retry for `create-pr` and `analyze-diff` commands (#49)
151
+ - **What changed**: Both commands now use `executeClaudeWithRetry()` with exponential backoff (2s, 4s, 8s delays)
152
+ - **Impact**: PR creation and diff analysis now automatically recover from transient Claude API errors
153
+ - **Files changed**:
154
+ - `lib/utils/claude-client.js:676-745,846` - Created reusable `withRetry()` wrapper and `executeClaudeWithRetry()` export
155
+ - `bin/claude-hooks:11,972,1234` - Updated create-pr and analyze-diff to use retry logic
156
+
157
+ ### 🐛 Fixed
158
+
159
+ - **Windows WSL timeout** - Increased WSL availability check from 3s to 15s to handle system load (#49)
160
+ - `lib/config.js:78` - Made configurable via `config.system.wslCheckTimeout`
161
+ - `lib/utils/claude-client.js:107` - Uses config value for WSL check
162
+ - **Duplicate task ID logging** - Removed redundant log in prepare-commit-msg (#49)
163
+ - `lib/hooks/prepare-commit-msg.js:191-193` - Removed duplicate logger.info call
164
+
165
+ ### 🎯 Improved
166
+
167
+ - **Error diagnostics** - Added timing information to all error contexts (#49)
168
+ - `lib/utils/claude-client.js:248-340` - Added `elapsedTime`, `timeoutValue`, `retryAttempt` to errors
169
+ - `lib/utils/claude-diagnostics.js:118-143,187-344` - Created `formatTimingInfo()` helper, updated all error formatters
170
+
8
171
  ## [2.7.1] - 2025-12-22
9
172
 
10
173
  ### 🐛 Fixed
package/README.md CHANGED
@@ -65,6 +65,12 @@ claude-hooks --debug true
65
65
 
66
66
  # Ver estado de debug
67
67
  claude-hooks --debug status
68
+
69
+ # Ver estadísticas de telemetría (v2.9.0+, habilitada por defecto)
70
+ claude-hooks telemetry show
71
+
72
+ # Limpiar datos de telemetría (v2.9.0+)
73
+ claude-hooks telemetry clear
68
74
  ```
69
75
 
70
76
  ### 📦 Instalación y Gestión
@@ -164,16 +170,20 @@ export GITHUB_PERSONAL_ACCESS_TOKEN="ghp_tu_token_aqui"
164
170
  ### 4. Configurar reviewers y labels (opcional)
165
171
 
166
172
  ```bash
167
- # Ver templates/config.github.example.json para formato completo
173
+ # Ver .claude/config_example/ para más ejemplos
168
174
  cat > .claude/config.json << 'EOF'
169
175
  {
170
- "github": {
171
- "pr": {
172
- "defaultBase": "develop",
173
- "reviewers": ["tu-usuario-github", "teammate"],
174
- "labelRules": {
175
- "backend": ["backend", "java"],
176
- "frontend": ["frontend", "react"]
176
+ "version": "2.8.0",
177
+ "preset": "backend",
178
+ "overrides": {
179
+ "github": {
180
+ "pr": {
181
+ "defaultBase": "develop",
182
+ "reviewers": ["tu-usuario-github", "teammate"],
183
+ "labelRules": {
184
+ "backend": ["backend", "java"],
185
+ "frontend": ["frontend", "react"]
186
+ }
177
187
  }
178
188
  }
179
189
  }
@@ -206,40 +216,41 @@ Ver `templates/config.github.example.json` para configuración avanzada (reviewe
206
216
 
207
217
  Toda idea es bienvenida, aunque parezca espantosa. Si hay bugs, incluirlos también. Dónde? en https://github.com/mscope-S-L/git-hooks/issues/new.
208
218
 
209
- ### 🔧 Configuración Avanzada (v2.2.0+)
219
+ ### 🔧 Configuración Avanzada (v2.8.0+)
210
220
 
211
221
  ```bash
212
- # Configuración vía .claude/config.json
222
+ # Configuración vía .claude/config.json (v2.8.0+)
213
223
  .claude/
214
- ├── config.json # Configuración principal (v2.2.0+)
215
- ├── CLAUDE_PRE_COMMIT.md # Personalizar criterios (override)
216
- └── CLAUDE_ANALYSIS_PROMPT.md # Modificar prompt (override)
217
-
218
- # Ejemplo de config.json (todas las opciones son opcionales)
224
+ ├── config.json # Configuración principal (formato simplificado)
225
+ ├── config_example/ # Ejemplos de configuración
226
+ │ ├── config.example.json # Configuración básica
227
+ │ └── config.advanced.example.json # Parámetros avanzados
228
+ └── prompts/ # Templates de prompts (v2.8.0+)
229
+ ├── CLAUDE_PRE_COMMIT.md # Criterios de análisis
230
+ └── CLAUDE_ANALYSIS_PROMPT.md # Template del prompt
231
+
232
+ # Ejemplo de config.json v2.8.0 (formato simplificado)
219
233
  cat > .claude/config.json << 'EOF'
220
234
  {
235
+ "version": "2.8.0",
221
236
  "preset": "backend",
222
- "analysis": {
223
- "maxFileSize": 1000000,
224
- "maxFiles": 12,
225
- "timeout": 150000
226
- },
227
- "commitMessage": {
228
- "autoKeyword": "auto",
229
- "timeout": 180000,
230
- "taskIdPattern": "([A-Z]{1,3}[-\\s]\\d{3,5})"
231
- },
232
- "subagents": {
233
- "enabled": true,
234
- "model": "haiku",
235
- "batchSize": 3
236
- },
237
- "system": {
238
- "debug": true
237
+ "overrides": {
238
+ "github": {
239
+ "pr": {
240
+ "defaultBase": "main",
241
+ "reviewers": ["tech-lead"]
242
+ }
243
+ },
244
+ "subagents": {
245
+ "batchSize": 2
246
+ }
239
247
  }
240
248
  }
241
249
  EOF
242
250
 
251
+ # Para configuración avanzada, consultar:
252
+ # .claude/config_example/config.advanced.example.json
253
+
243
254
  # Personalizar patrón de task-id
244
255
  # Default: 1-3 letras + separador + 3-5 dígitos
245
256
  # Ejemplos válidos: ABC-12345, IX-123, DE 4567
@@ -357,31 +368,40 @@ git commit -m "fix: resolver issues"
357
368
  ### ⚡ Tips y Trucos
358
369
 
359
370
  1. **Mensaje automático**: Usa `"auto"` como mensaje para que Claude lo genere con task-id automático
360
- 2. **Task-ID pattern**: Default 1-3 letras + separador + 3-5 dígitos (ABC-12345, IX-123). Configurable en `.claude/config.json` → `commitMessage.taskIdPattern`
371
+ 2. **Task-ID pattern**: Default 1-3 letras + separador + 3-5 dígitos (ABC-12345, IX-123). Configurable en `.claude/config_example/config.advanced.example.json`
361
372
  3. **Skip auth**: Usa `--skip-auth` en CI/CD o desarrollo local
362
373
  4. **Force install**: Usa `--force` para reinstalar sin confirmación
363
- 5. **Debug**: Activa con `claude-hooks --debug true` o en `.claude/config.json`: `{"system": {"debug": true}}`
364
- 6. **Archivos grandes**: Se omiten automáticamente archivos > 1MB
365
- 7. **Límite de archivos**: Máximo 30 archivos por commit (configurable)
374
+ 5. **Debug**: Activa con `claude-hooks --debug true`
375
+ 6. **Archivos grandes**: Se omiten automáticamente archivos > 1MB (hardcoded desde v2.8.0)
376
+ 7. **Límite de archivos**: Máximo 20 archivos por commit (hardcoded desde v2.8.0)
377
+
378
+ ### 🚀 Parallel Analysis (Enabled by default desde v2.8.0)
379
+
380
+ **When analyzing 3+ files**, parallel execution runs multiple Claude CLI processes simultaneously for faster analysis.
366
381
 
367
- ### 🚀 Parallel Analysis (v2.2.0+)
382
+ **Configuración automática (hardcoded):**
383
+ - ✅ **Enabled**: `true` (siempre activo)
384
+ - ⚡ **Model**: `haiku` (rápido y económico)
385
+ - 📦 **BatchSize**: `3` files per batch (puede overridearse)
368
386
 
369
- **When analyzing 3+ files**, parallel execution runs multiple Claude CLI processes simultaneously for faster analysis:
387
+ **Customizar batch size (opcional):**
370
388
 
371
389
  ```bash
372
- # Configure in .claude/config.json
390
+ # En .claude/config.json v2.8.0
373
391
  {
374
- "subagents": {
375
- "enabled": true,
376
- "model": "haiku",
377
- "batchSize": 2
392
+ "version": "2.8.0",
393
+ "preset": "backend",
394
+ "overrides": {
395
+ "subagents": {
396
+ "batchSize": 2
397
+ }
378
398
  }
379
399
  }
380
400
  ```
381
401
 
382
- **Model options:**
402
+ **Model options (solo en config avanzado):**
383
403
 
384
- - `haiku` - Fast & cheap (default, recommended)
404
+ - `haiku` - Fast & cheap (default)
385
405
  - `sonnet` - Balanced quality/speed
386
406
  - `opus` - Maximum quality (slower)
387
407
 
@@ -422,9 +442,9 @@ git commit -m "fix: resolver issues"
422
442
 
423
443
  **Archivos clave para modificar:**
424
444
 
425
- - `.claude/config.json` - Configuración principal (v2.2.0+)
426
- - `.claude/CLAUDE_PRE_COMMIT.md` - Criterios (backend/frontend/data/db)
427
- - `.claude/CLAUDE_ANALYSIS_PROMPT.md` - Template del prompt
445
+ - `.claude/config.json` - Configuración principal (v2.8.0+)
446
+ - `.claude/prompts/CLAUDE_PRE_COMMIT.md` - Criterios (backend/frontend/data/db)
447
+ - `.claude/prompts/CLAUDE_ANALYSIS_PROMPT.md` - Template del prompt
428
448
 
429
449
  **Crear o modificar presets personalizados:**
430
450
 
@@ -439,7 +459,7 @@ cat templates/CUSTOMIZATION_GUIDE.md
439
459
  **Ejemplo:**
440
460
 
441
461
  ```bash
442
- vim .claude/CLAUDE_PRE_COMMIT.md # Agregar reglas API REST/Spring Boot
462
+ vim .claude/prompts/CLAUDE_PRE_COMMIT.md # Agregar reglas API REST/Spring Boot
443
463
  ```
444
464
 
445
465
  ## 🔧 Configuración Previa Importante
@@ -537,8 +557,8 @@ Si no existe un `.gitignore`, se creará uno nuevo. Si ya existe, las entradas s
537
557
  - Omite archivos mayores a 1MB
538
558
  - Límite de 30 archivos por commit
539
559
  3. **Construye prompt inteligente**:
540
- - Usa template de prompt desde `.claude/CLAUDE_ANALYSIS_PROMPT*.md`
541
- - Lee las pautas desde `.claude/CLAUDE_PRE_COMMIT*.md`
560
+ - Usa template de prompt desde `.claude/prompts/CLAUDE_ANALYSIS_PROMPT*.md`
561
+ - Lee las pautas desde `.claude/prompts/CLAUDE_PRE_COMMIT*.md`
542
562
  - Incluye el diff completo para archivos nuevos
543
563
  - Muestra solo cambios para archivos existentes
544
564
  4. **Envía a Claude CLI para revisión**