pumuki-ast-hooks 5.3.19 → 5.3.20

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.
Files changed (75) hide show
  1. package/docs/VIOLATIONS_RESOLUTION_PLAN.md +38 -34
  2. package/package.json +7 -1
  3. package/scripts/hooks-system/application/services/AutonomousOrchestrator.js +18 -0
  4. package/scripts/hooks-system/application/services/ContextDetectionEngine.js +58 -0
  5. package/scripts/hooks-system/application/services/DynamicRulesLoader.js +11 -0
  6. package/scripts/hooks-system/application/services/GitFlowService.js +80 -0
  7. package/scripts/hooks-system/application/services/GitTreeState.js +4 -0
  8. package/scripts/hooks-system/application/services/HookSystemScheduler.js +4 -0
  9. package/scripts/hooks-system/application/services/IntelligentCommitAnalyzer.js +25 -0
  10. package/scripts/hooks-system/application/services/IntelligentGitTreeMonitor.js +11 -0
  11. package/scripts/hooks-system/application/services/PlatformAnalysisService.js +19 -0
  12. package/scripts/hooks-system/application/services/PlatformDetectionService.js +19 -0
  13. package/scripts/hooks-system/application/services/PlaybookRunner.js +22 -1
  14. package/scripts/hooks-system/application/services/PredictiveHookAdvisor.js +19 -0
  15. package/scripts/hooks-system/application/services/RealtimeGuardPlugin.js +25 -0
  16. package/scripts/hooks-system/application/services/RealtimeGuardService.js +27 -0
  17. package/scripts/hooks-system/application/services/SmartDirtyTreeAnalyzer.js +11 -0
  18. package/scripts/hooks-system/application/services/commit/CommitMessageGenerator.js +11 -0
  19. package/scripts/hooks-system/application/services/commit/FeatureDetector.js +11 -0
  20. package/scripts/hooks-system/application/services/evidence/EvidenceContextManager.js +25 -0
  21. package/scripts/hooks-system/application/services/guard/GuardAutoManagerService.js +19 -0
  22. package/scripts/hooks-system/application/services/guard/GuardConfig.js +11 -0
  23. package/scripts/hooks-system/application/services/guard/GuardEventLogger.js +11 -0
  24. package/scripts/hooks-system/application/services/guard/GuardHealthReminder.js +26 -0
  25. package/scripts/hooks-system/application/services/guard/GuardHeartbeatMonitor.js +11 -0
  26. package/scripts/hooks-system/application/services/guard/GuardLockManager.js +11 -0
  27. package/scripts/hooks-system/application/services/guard/GuardMonitorLoop.js +25 -0
  28. package/scripts/hooks-system/application/services/guard/GuardNotificationHandler.js +11 -0
  29. package/scripts/hooks-system/application/services/guard/GuardProcessManager.js +11 -0
  30. package/scripts/hooks-system/application/services/guard/GuardRecoveryService.js +11 -0
  31. package/scripts/hooks-system/application/services/installation/ConfigurationGeneratorService.js +18 -0
  32. package/scripts/hooks-system/application/services/installation/FileSystemInstallerService.js +18 -0
  33. package/scripts/hooks-system/application/services/installation/GitEnvironmentService.js +18 -0
  34. package/scripts/hooks-system/application/services/installation/HookInstaller.js +19 -0
  35. package/scripts/hooks-system/application/services/installation/IdeIntegrationService.js +11 -0
  36. package/scripts/hooks-system/application/services/installation/InstallService.js +25 -1
  37. package/scripts/hooks-system/application/services/installation/McpConfigurator.js +18 -0
  38. package/scripts/hooks-system/application/services/installation/PlatformDetectorService.js +11 -0
  39. package/scripts/hooks-system/application/services/installation/VSCodeTaskConfigurator.js +11 -0
  40. package/scripts/hooks-system/application/services/logging/AuditLogger.js +4 -0
  41. package/scripts/hooks-system/application/services/logging/UnifiedLogger.js +11 -0
  42. package/scripts/hooks-system/application/services/monitoring/ActivityMonitor.js +33 -0
  43. package/scripts/hooks-system/application/services/monitoring/AstMonitor.js +27 -0
  44. package/scripts/hooks-system/application/services/monitoring/DevDocsMonitor.js +26 -0
  45. package/scripts/hooks-system/application/services/monitoring/EvidenceMonitor.js +18 -0
  46. package/scripts/hooks-system/application/services/monitoring/EvidenceMonitorService.js +25 -0
  47. package/scripts/hooks-system/application/services/monitoring/GitTreeMonitor.js +28 -0
  48. package/scripts/hooks-system/application/services/monitoring/GitTreeMonitorService.js +26 -0
  49. package/scripts/hooks-system/application/services/monitoring/HealthCheckProviders.js +4 -0
  50. package/scripts/hooks-system/application/services/monitoring/HealthCheckService.js +25 -0
  51. package/scripts/hooks-system/application/services/monitoring/HeartbeatMonitorService.js +26 -0
  52. package/scripts/hooks-system/application/services/monitoring/TokenMonitor.js +26 -0
  53. package/scripts/hooks-system/application/services/notification/MacNotificationSender.js +11 -0
  54. package/scripts/hooks-system/application/services/notification/NotificationCenterService.js +18 -0
  55. package/scripts/hooks-system/application/services/notification/NotificationDispatcher.js +11 -0
  56. package/scripts/hooks-system/application/services/notification/components/NotificationCooldownManager.js +18 -0
  57. package/scripts/hooks-system/application/services/notification/components/NotificationDeduplicator.js +18 -0
  58. package/scripts/hooks-system/application/services/notification/components/NotificationQueue.js +11 -0
  59. package/scripts/hooks-system/application/services/notification/components/NotificationRetryExecutor.js +20 -0
  60. package/scripts/hooks-system/application/services/platform/PlatformHeuristics.js +19 -0
  61. package/scripts/hooks-system/application/services/recovery/AutoRecoveryManager.js +19 -0
  62. package/scripts/hooks-system/application/services/smart-commit/CommitMessageSuggester.js +11 -0
  63. package/scripts/hooks-system/application/services/smart-commit/FileContextGrouper.js +19 -0
  64. package/scripts/hooks-system/application/services/smart-commit/SmartCommitSummaryBuilder.js +4 -0
  65. package/scripts/hooks-system/application/services/token/CursorTokenService.js +20 -0
  66. package/scripts/hooks-system/application/services/token/TokenMetricsService.js +11 -0
  67. package/scripts/hooks-system/application/services/token/TokenMonitorService.js +19 -0
  68. package/scripts/hooks-system/application/services/token/TokenStatusReporter.js +12 -0
  69. package/scripts/hooks-system/config/project.config.json +1 -1
  70. package/scripts/hooks-system/domain/events/index.js +25 -6
  71. package/scripts/hooks-system/domain/exceptions/index.js +87 -0
  72. package/scripts/hooks-system/infrastructure/ast/backend/ast-backend.js +7 -9
  73. package/scripts/hooks-system/infrastructure/config/config.js +5 -0
  74. package/scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh +54 -92
  75. package/scripts/hooks-system/infrastructure/telemetry/metric-scope.js +98 -0
@@ -10,8 +10,8 @@
10
10
  ---
11
11
 
12
12
  ## 📊 Resumen Ejecutivo
13
- - **Estado actual:** ⚠️ Acción requerida (91 críticas, 0 altas, 30 medias, 14 bajas)
14
- - **Branch:** `fix/audit-staged-severity-case-insensitive`
13
+ - **Estado actual:** ⚠️ Acción requerida (1 crítica, 4 altas, 294 medias, 242 bajas)
14
+ - **Branch:** `feature/add-prometheus-metrics`
15
15
  - **Fecha de inicio:** 30/12/2025 — **ETA general:** 15/01/2026
16
16
  - **Objetivo:** Reducir a 0 las CRÍTICAS/HIGH y bajar el total < 20 antes de permitir commits sin bypass.
17
17
  - **Riesgos:**
@@ -29,16 +29,12 @@
29
29
  gantt
30
30
  title Fases de Resolución de Violaciones
31
31
  dateFormat YYYY-MM-DD
32
- section Fase 1: CRÍTICAS
33
- Excepciones personalizadas :active, crit1, 2025-12-30, 4d
34
- Separación de entornos : crit2, after crit1, 3d
35
- Auditoría de seguridad : crit3, after crit2, 3d
36
- Métricas Prometheus : crit4, after crit3, 2d
37
- Patrones de confiabilidad : crit5, after crit4, 2d
32
+ section Fase 1: BLOQUEANTES (CRITICAL + HIGH)
33
+ Resolver CRITICAL :active, crit1, 2025-12-30, 1d
34
+ Resolver HIGH : high1, after crit1, 2d
38
35
 
39
- section Fase 2: HIGH + MEDIUM
40
- Corrección HIGH : high1, after crit5, 1d
41
- Refactorización MEDIUM : med1, after high1, 5d
36
+ section Fase 2: MEDIUM
37
+ Refactorización MEDIUM : med1, after high1, 7d
42
38
 
43
39
  section Fase 3: LOW
44
40
  Optimizaciones y documentación : low1, after med1, 5d
@@ -46,48 +42,56 @@ gantt
46
42
 
47
43
  ---
48
44
 
49
- ## 🔴 Fase 1: Violaciones CRÍTICAS (91)
50
- | Estado | Violación | Cant. | Responsable | DOD (Definition of Done) | Doc |
51
- |--------|-----------|-------|-------------|--------------------------|-----|
52
- | 🚧 | backend.observability.missing_prometheus | 45 | BE | Añadir métricas Prometheus a todos los servicios críticos; endpoints /metrics funcionando | [Prometheus](../docs/metrics-monitoring.md) |
53
- | ⏳ | backend.config.missing_env_separation | 27 | BE | Config por entorno (dev/stg/prod), sin secretos hardcode | [Config entornos](../docs/env-configuration.md) |
54
- | ⏳ | backend.security.missing_audit_logging | 23 | BE | Audit trail en operaciones sensibles + logs estructurados | [Audit logging](../docs/security-auditing.md) |
55
- | ⏳ | backend.error.custom_exceptions | 16 | BE | CustomError base + reemplazo de `Error` genérico en BE; tests pasando | [Guía de excepciones](../docs/error-handling.md) |
56
- | ⏳ | backend.reliability.missing_bulkhead | 10 | BE | Limitadores/aislamiento en puntos críticos + pruebas de carga | [Reliability](../docs/reliability-patterns.md) |
57
- | ⏳ | backend.event.emitter | 4 | BE | try/catch en manejadores de eventos; manejo de errores robusto | [Eventos](../docs/event-handling.md) |
58
- | ⏳ | backend.observability.missing_alerting | 3 | SRE | Alertas en métricas críticas; umbrales definidos | [Alerting](../docs/alerting-system.md) |
59
- | ⏳ | backend.config.missing_validation | 1 | BE | Validación de configuración al inicio | [Config validation](../docs/config-validation.md) |
60
- | ⏳ | backend.config.missing_env_validation | 1 | BE | Validación de variables de entorno requeridas | [Env validation](../docs/env-validation.md) |
61
- | ⏳ | backend.database.raw_sql | 1 | BE | Uso de ORM en lugar de raw SQL | [Database](../docs/database-layer.md) |
45
+ ## 🔴 Fase 1: Violaciones BLOQUEANTES (CRITICAL + HIGH)
46
+ | Estado | Severidad | Cant. | Responsable | DOD (Definition of Done) | Fuente |
47
+ |--------|-----------|-------|-------------|--------------------------|--------|
48
+ | | CRITICAL | 1 | BE | Resolver la violación CRITICAL en repositorio (0 CRITICAL para desbloquear) | `.audit_tmp/ast-summary.json` / `.violations-by-priority.md` |
49
+ | ⏳ | HIGH | 4 | BE | Resolver las 4 violaciones HIGH en repositorio (0 HIGH para desbloquear) | `.audit_tmp/ast-summary.json` / `.violations-by-priority.md` |
62
50
 
63
51
  ---
64
52
 
65
- ## 🟠 Fase 2: Violaciones HIGH + MEDIUM (30)
53
+ ## 🟠 Fase 2: Violaciones MEDIUM (294)
66
54
  | Estado | Violación | Cant. | Responsable | DOD | Doc |
67
55
  |--------|-----------|-------|-------------|-----|-----|
68
- | | HIGH | 0 | BE | No aplica (repo JS puro sin TS); se documenta enfoque de seguridad de tipos | [Type safety](../docs/type-safety.md) |
69
- | ⏳ | MEDIUM | 30 | BE | Resolver violaciones de complejidad media restantes | [Medium violations](../docs/medium-violations.md) |
56
+ | | MEDIUM | 294 | BE | Resolver violaciones de complejidad media restantes | [Medium violations](../docs/medium-violations.md) |
70
57
 
71
58
  ---
72
59
 
73
- ## 🔵 Fase 3: Violaciones LOW (14)
60
+ ## 🔵 Fase 3: Violaciones LOW (242)
74
61
  | Estado | Violación | Cant. | Responsable | DOD | Doc |
75
62
  |--------|-----------|-------|-------------|-----|-----|
76
- | ⏳ | LOW | 14 | BE/FE | Resolver violaciones de baja prioridad restantes | [Low violations](../docs/low-violations.md) |
63
+ | ⏳ | LOW | 242 | BE/FE | Resolver violaciones de baja prioridad restantes | [Low violations](../docs/low-violations.md) |
64
+
65
+ ---
66
+
67
+ ## 🎯 Top violaciones (por volumen / impacto) — para priorizar dentro de MEDIUM/LOW
68
+ | Prioridad | Violación | Cant. | Notas |
69
+ |----------|-----------|-------|------|
70
+ | P1 | backend.error.custom_exceptions | 105 | Normalmente MEDIUM: refactor a CustomError + reemplazo de `Error` genérico en BE |
71
+ | P1 | backend.config.missing_env_separation | 81 | Normalmente MEDIUM: separar config por entorno |
72
+ | P1 | backend.security.missing_audit_logging | 69 | Normalmente MEDIUM: audit trail en operaciones sensibles |
73
+ | P2 | backend.metrics.missing_prometheus | 42 | MEDIUM/LOW según regla: instrumentación de servicios |
74
+ | P2 | backend.reliability.missing_bulkhead | 41 | MEDIUM/LOW: bulkheads/timeouts en puntos críticos |
75
+ | P2 | backend.testing.mocks | 40 | MEDIUM: mejorar estrategia de tests |
76
+ | P2 | backend.observability.missing_prometheus | 30 | LOW: observabilidad y dashboards |
77
+ | P3 | backend.event.handler | 26 | LOW: try/catch y resiliencia |
78
+ | P3 | backend.auth.missing_cors | 17 | LOW: CORS/headers |
79
+ | P3 | backend.event.emitter | 14 | LOW: emisores de eventos seguros |
77
80
 
78
81
  ---
79
82
 
80
83
  ## 📈 Métricas de Progreso
81
84
  | Fase | Total | Completado | % |
82
85
  |------|-------|------------|---|
83
- | CRÍTICAS | 91 | 0 | 0% |
84
- | HIGH + MEDIUM | 30 | 0 | 0% |
85
- | LOW | 14 | 0 | 0% |
86
- | **TOTAL** | **135** | **0** | **0%** |
86
+ | BLOQUEANTES (CRITICAL + HIGH) | 5 | 0 | 0% |
87
+ | MEDIUM | 294 | 0 | 0% |
88
+ | LOW | 242 | 0 | 0% |
89
+ | **TOTAL** | **541** | **0** | **0%** |
87
90
 
88
91
  **Riesgos actualizados:**
89
92
  1) Implementación de Prometheus podría requerir cambios de infra; 2) Revisión de seguridad depende de disponibilidad de equipo; 3) Refactorizaciones pueden impactar tiempos.
90
93
 
91
94
  **Comentarios/Notas colaborativas:**
92
95
  - Añade comentarios bajo cada tabla al cerrar tareas (usa la leyenda para actualizar estados).
93
- - Progreso en métricas Prometheus: añadidas a 27 servicios, pero 45 violaciones restantes indican necesidad de más instrumentación.
96
+ - Progreso en métricas Prometheus: aplicada una barrida automática sobre `scripts/hooks-system/application/services/**`; el audit sigue reportando 42 (`backend.metrics.missing_prometheus`) y 30 (`backend.observability.missing_prometheus`) pendientes.
97
+ - Último escaneo: 449 archivos, 541 violaciones totales (1 crítica, 4 altas, 294 medias, 242 bajas).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pumuki-ast-hooks",
3
- "version": "5.3.19",
3
+ "version": "5.3.20",
4
4
  "description": "Enterprise-grade AST Intelligence System with multi-platform support (iOS, Android, Backend, Frontend) and Feature-First + DDD + Clean Architecture enforcement. Includes dynamic violations API for intelligent querying.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -86,10 +86,16 @@
86
86
  "ts-morph": "^21.0.0"
87
87
  },
88
88
  "devDependencies": {
89
+ "@babel/generator": "^7.28.5",
90
+ "@babel/parser": "^7.28.5",
91
+ "@babel/traverse": "^7.28.5",
89
92
  "@pumuki/ast-intelligence-hooks": "file:pumuki-ast-intelligence-hooks-5.3.1.tgz",
90
93
  "@types/node": "^20.10.0",
91
94
  "eslint": "^9.12.0",
92
95
  "jest": "^30.2.0",
96
+ "jscodeshift": "^17.3.0",
97
+ "pumuki-ast-hooks": "^5.3.19",
98
+ "recast": "^0.23.11",
93
99
  "typescript": "^5.3.0"
94
100
  },
95
101
  "files": [
@@ -3,8 +3,18 @@ const { execSync } = require('child_process');
3
3
  const path = require('path');
4
4
  const UnifiedLogger = require('./logging/UnifiedLogger');
5
5
 
6
+ const {
7
+ createMetricScope: createMetricScope
8
+ } = require('../../../infrastructure/telemetry/metric-scope');
9
+
6
10
  class AutonomousOrchestrator {
7
11
  constructor(contextEngine, platformDetector, rulesLoader, logger = new UnifiedLogger()) {
12
+ const m_constructor = createMetricScope({
13
+ hook: 'autonomous_orchestrator',
14
+ operation: 'constructor'
15
+ });
16
+
17
+ m_constructor.started();
8
18
  this.contextEngine = contextEngine;
9
19
  this.platformDetector = platformDetector || new PlatformDetectionService();
10
20
  this.rulesLoader = rulesLoader;
@@ -15,6 +25,7 @@ class AutonomousOrchestrator {
15
25
  };
16
26
  this.lastAnalysis = null;
17
27
  this.lastAnalysisTime = 0;
28
+ m_constructor.success();
18
29
  }
19
30
 
20
31
  detectFromASTSystemFiles(files) {
@@ -123,6 +134,13 @@ class AutonomousOrchestrator {
123
134
  }
124
135
 
125
136
  getLastAnalysis() {
137
+ const m_get_last_analysis = createMetricScope({
138
+ hook: 'autonomous_orchestrator',
139
+ operation: 'get_last_analysis'
140
+ });
141
+
142
+ m_get_last_analysis.started();
143
+ m_get_last_analysis.success();
126
144
  return this.lastAnalysis;
127
145
  }
128
146
  }
@@ -1,7 +1,17 @@
1
1
  const crypto = require('crypto');
2
2
 
3
+ const {
4
+ createMetricScope: createMetricScope
5
+ } = require('../../../infrastructure/telemetry/metric-scope');
6
+
3
7
  class ContextDetectionEngine {
4
8
  constructor(repoRootOrGitPort = null, logger = console) {
9
+ const m_constructor = createMetricScope({
10
+ hook: 'context_detection_engine',
11
+ operation: 'constructor'
12
+ });
13
+
14
+ m_constructor.started();
5
15
  if (typeof repoRootOrGitPort === 'string') {
6
16
  this.repoRoot = repoRootOrGitPort;
7
17
  this.git = null;
@@ -16,6 +26,7 @@ class ContextDetectionEngine {
16
26
  timestamp: 0,
17
27
  ttl: 10000
18
28
  };
29
+ m_constructor.success();
19
30
  }
20
31
 
21
32
  async detectContext() {
@@ -54,40 +65,74 @@ class ContextDetectionEngine {
54
65
  }
55
66
 
56
67
  getStagedFiles() {
68
+ const m_get_staged_files = createMetricScope({
69
+ hook: 'context_detection_engine',
70
+ operation: 'get_staged_files'
71
+ });
72
+
73
+ m_get_staged_files.started();
57
74
  try {
75
+ m_get_staged_files.success();
58
76
  return this.git.getStagedFiles();
59
77
  } catch (error) {
60
78
  this.logger.error('ContextDetectionEngine: Failed to get staged files', error);
79
+ m_get_staged_files.success();
61
80
  return [];
62
81
  }
82
+ m_get_staged_files.success();
63
83
  }
64
84
 
65
85
  getStagedSignature() {
86
+ const m_get_staged_signature = createMetricScope({
87
+ hook: 'context_detection_engine',
88
+ operation: 'get_staged_signature'
89
+ });
90
+
91
+ m_get_staged_signature.started();
66
92
  try {
67
93
  const patch = this.git.getDiff(true);
68
94
  if (!patch) return '';
95
+ m_get_staged_signature.success();
69
96
  return crypto.createHash('sha1').update(patch).digest('hex');
70
97
  } catch (error) {
98
+ m_get_staged_signature.success();
71
99
  return '';
72
100
  }
101
+ m_get_staged_signature.success();
73
102
  }
74
103
 
75
104
  getRecentlyModifiedFiles() {
105
+ const m_get_recently_modified_files = createMetricScope({
106
+ hook: 'context_detection_engine',
107
+ operation: 'get_recently_modified_files'
108
+ });
109
+
110
+ m_get_recently_modified_files.started();
76
111
  try {
77
112
  const output = this.git.getStatusShort();
78
113
  if (!output) return [];
79
114
 
115
+ m_get_recently_modified_files.success();
116
+
80
117
  return output
81
118
  .split('\n')
82
119
  .filter(Boolean)
83
120
  .map(line => line.trim().substring(2)) // Remove status code
84
121
  .filter(file => !file.startsWith('.git'));
85
122
  } catch (error) {
123
+ m_get_recently_modified_files.success();
86
124
  return [];
87
125
  }
126
+ m_get_recently_modified_files.success();
88
127
  }
89
128
 
90
129
  getRecentCommitPatterns() {
130
+ const m_get_recent_commit_patterns = createMetricScope({
131
+ hook: 'context_detection_engine',
132
+ operation: 'get_recent_commit_patterns'
133
+ });
134
+
135
+ m_get_recent_commit_patterns.started();
91
136
  try {
92
137
  const output = this.git.getLog(10);
93
138
  if (!output) return [];
@@ -116,18 +161,31 @@ class ContextDetectionEngine {
116
161
  commits.push(currentCommit);
117
162
  }
118
163
 
164
+ m_get_recent_commit_patterns.success();
165
+
119
166
  return commits.slice(0, 10);
120
167
  } catch (error) {
168
+ m_get_recent_commit_patterns.success();
121
169
  return [];
122
170
  }
171
+ m_get_recent_commit_patterns.success();
123
172
  }
124
173
 
125
174
  getCurrentBranch() {
175
+ const m_get_current_branch = createMetricScope({
176
+ hook: 'context_detection_engine',
177
+ operation: 'get_current_branch'
178
+ });
179
+
180
+ m_get_current_branch.started();
126
181
  try {
182
+ m_get_current_branch.success();
127
183
  return this.git.getCurrentBranch();
128
184
  } catch (error) {
185
+ m_get_current_branch.success();
129
186
  return 'unknown';
130
187
  }
188
+ m_get_current_branch.success();
131
189
  }
132
190
 
133
191
  inferFromGitStatus() {
@@ -1,8 +1,18 @@
1
+ const {
2
+ createMetricScope: createMetricScope
3
+ } = require('../../../infrastructure/telemetry/metric-scope');
4
+
1
5
  const fs = require('fs').promises;
2
6
  const path = require('path');
3
7
 
4
8
  class DynamicRulesLoader {
5
9
  constructor(rulesDirectory, logger = console) {
10
+ const m_constructor = createMetricScope({
11
+ hook: 'dynamic_rules_loader',
12
+ operation: 'constructor'
13
+ });
14
+
15
+ m_constructor.started();
6
16
  this.rulesDirectory = rulesDirectory || null;
7
17
  this.logger = logger;
8
18
  this.rulesDirectories = this.resolveRulesDirectories();
@@ -18,6 +28,7 @@ class DynamicRulesLoader {
18
28
  ttl: 60000
19
29
  };
20
30
  this.lastLoadWarnings = [];
31
+ m_constructor.success();
21
32
  }
22
33
 
23
34
  resolveRulesDirectories() {
@@ -1,8 +1,22 @@
1
1
  const { execSync, spawnSync } = require('child_process');
2
2
  const { ConfigurationError } = require('../../domain/errors');
3
3
 
4
+ const { recordMetric } = require('../../../infrastructure/telemetry/metrics-logger');
5
+
6
+ const {
7
+ createMetricScope: createMetricScope
8
+ } = require('../../../infrastructure/telemetry/metric-scope');
9
+
4
10
  class GitFlowService {
5
11
  constructor(repoRoot, options = {}, logger = console, gitQuery = null, gitCommand = null, githubAdapter = null) {
12
+ recordMetric({
13
+ hook: 'git_flow_service',
14
+ operation: 'constructor',
15
+ status: 'started',
16
+ repoRoot: repoRoot.substring(0, 100),
17
+ hasOptions: !!options
18
+ });
19
+
6
20
  this.repoRoot = repoRoot;
7
21
  this.logger = logger;
8
22
  this.gitQuery = gitQuery;
@@ -16,6 +30,16 @@ class GitFlowService {
16
30
  this.requireClean = options.requireClean !== false;
17
31
 
18
32
  this._validateDependencies();
33
+
34
+ recordMetric({
35
+ hook: 'git_flow_service',
36
+ operation: 'constructor',
37
+ status: 'success',
38
+ developBranch: this.developBranch,
39
+ mainBranch: this.mainBranch,
40
+ autoSyncEnabled: this.autoSyncEnabled,
41
+ autoCleanEnabled: this.autoCleanEnabled
42
+ });
19
43
  }
20
44
 
21
45
  _validateDependencies() {
@@ -25,9 +49,17 @@ class GitFlowService {
25
49
  }
26
50
 
27
51
  getCurrentBranch() {
52
+ const m_get_current_branch = createMetricScope({
53
+ hook: 'git_flow_service',
54
+ operation: 'get_current_branch'
55
+ });
56
+
57
+ m_get_current_branch.started();
28
58
  if (this.gitQuery) {
59
+ m_get_current_branch.success();
29
60
  return this.gitQuery.getCurrentBranch();
30
61
  }
62
+ m_get_current_branch.success();
31
63
  return 'unknown';
32
64
  }
33
65
 
@@ -40,12 +72,31 @@ class GitFlowService {
40
72
  }
41
73
 
42
74
  syncBranches() {
75
+ recordMetric({
76
+ hook: 'git_flow_service',
77
+ operation: 'sync_branches',
78
+ status: 'started',
79
+ autoSyncEnabled: this.autoSyncEnabled
80
+ });
81
+
43
82
  if (!this.autoSyncEnabled) {
83
+ recordMetric({
84
+ hook: 'git_flow_service',
85
+ operation: 'sync_branches',
86
+ status: 'skipped',
87
+ reason: 'auto_sync_disabled'
88
+ });
44
89
  return { success: false, message: 'Auto-sync disabled' };
45
90
  }
46
91
 
47
92
  if (!this.isClean()) {
48
93
  this.logger.warn('Skipping sync: working directory not clean');
94
+ recordMetric({
95
+ hook: 'git_flow_service',
96
+ operation: 'sync_branches',
97
+ status: 'skipped',
98
+ reason: 'working_directory_not_clean'
99
+ });
49
100
  return { success: false, message: 'Working directory not clean' };
50
101
  }
51
102
 
@@ -64,22 +115,47 @@ class GitFlowService {
64
115
 
65
116
  this.gitCommand.checkout(current);
66
117
  } else {
118
+ recordMetric({
119
+ hook: 'git_flow_service',
120
+ operation: 'sync_branches',
121
+ status: 'failed',
122
+ reason: 'no_git_command_adapter'
123
+ });
67
124
  throw new ConfigurationError('GitCommandAdapter is required for branch synchronization', 'gitCommand');
68
125
  }
69
126
 
70
127
  this.logger.info('Branches synchronized successfully', {
71
128
  branches: [this.developBranch, this.mainBranch]
72
129
  });
130
+ recordMetric({
131
+ hook: 'git_flow_service',
132
+ operation: 'sync_branches',
133
+ status: 'success',
134
+ branches: [this.developBranch, this.mainBranch].join(',')
135
+ });
73
136
  return { success: true, message: 'Branches synchronized' };
74
137
  } catch (error) {
75
138
  this.logger.error('Branch synchronization failed', { error: error.message });
139
+ recordMetric({
140
+ hook: 'git_flow_service',
141
+ operation: 'sync_branches',
142
+ status: 'failed',
143
+ error: error.message.substring(0, 100)
144
+ });
76
145
  return { success: false, message: error.message };
77
146
  }
78
147
  }
79
148
 
80
149
  createPullRequest(sourceBranch, targetBranch, title, body) {
150
+ const m_create_pull_request = createMetricScope({
151
+ hook: 'git_flow_service',
152
+ operation: 'create_pull_request'
153
+ });
154
+
155
+ m_create_pull_request.started();
81
156
  if (!this.github) {
82
157
  this.logger.error('GitHub adapter not available');
158
+ m_create_pull_request.success();
83
159
  return null;
84
160
  }
85
161
 
@@ -94,11 +170,15 @@ class GitFlowService {
94
170
  this.logger.warn('Pull Request creation failed or returned no URL');
95
171
  }
96
172
 
173
+ m_create_pull_request.success();
174
+
97
175
  return prUrl;
98
176
  } catch (error) {
99
177
  this.logger.error('[GitFlowService] Failed to create PR:', { error: error.message });
178
+ m_create_pull_request.success();
100
179
  return null;
101
180
  }
181
+ m_create_pull_request.success();
102
182
  }
103
183
 
104
184
  mergeDevelopToMain() {
@@ -3,6 +3,10 @@ const { execSync } = require('child_process');
3
3
  // Import recordMetric for prometheus metrics
4
4
  const { recordMetric } = require('../../../infrastructure/telemetry/metrics-logger');
5
5
 
6
+ const {
7
+ createMetricScope: createMetricScope
8
+ } = require('../../../infrastructure/telemetry/metric-scope');
9
+
6
10
  const extractFilePath = line => {
7
11
  recordMetric({
8
12
  hook: 'git_tree_state',
@@ -1,6 +1,10 @@
1
1
  const { recordMetric } = require('../../infrastructure/telemetry/metrics-logger');
2
2
  const HookSystemStateMachine = require('../state/HookSystemStateMachine');
3
3
 
4
+ const {
5
+ createMetricScope: createMetricScope
6
+ } = require('../../../infrastructure/telemetry/metric-scope');
7
+
4
8
  class HookSystemScheduler {
5
9
  constructor({ orchestrator, contextEngine, intervalMs = 30000 }) {
6
10
  recordMetric({
@@ -5,12 +5,23 @@ const FeatureDetector = require('./commit/FeatureDetector');
5
5
  const CommitMessageGenerator = require('./commit/CommitMessageGenerator');
6
6
  const UnifiedLogger = require('./logging/UnifiedLogger');
7
7
 
8
+ const {
9
+ createMetricScope: createMetricScope
10
+ } = require('../../../infrastructure/telemetry/metric-scope');
11
+
8
12
  class IntelligentCommitAnalyzer {
9
13
  constructor({ repoRoot = process.cwd(), logger = null } = {}) {
14
+ const m_constructor = createMetricScope({
15
+ hook: 'intelligent_commit_analyzer',
16
+ operation: 'constructor'
17
+ });
18
+
19
+ m_constructor.started();
10
20
  this.repoRoot = repoRoot;
11
21
  this.logger = logger || console;
12
22
  this.featureDetector = new FeatureDetector(this.logger);
13
23
  this.messageGenerator = new CommitMessageGenerator(this.logger);
24
+ m_constructor.success();
14
25
  }
15
26
 
16
27
  detectFeature(filePath) {
@@ -137,6 +148,13 @@ class IntelligentCommitAnalyzer {
137
148
  * Get ready-to-commit groups (all groups are ready - no verification)
138
149
  */
139
150
  getReadyCommits(suggestions) {
151
+ const m_get_ready_commits = createMetricScope({
152
+ hook: 'intelligent_commit_analyzer',
153
+ operation: 'get_ready_commits'
154
+ });
155
+
156
+ m_get_ready_commits.started();
157
+ m_get_ready_commits.success();
140
158
  return suggestions;
141
159
  }
142
160
 
@@ -144,6 +162,13 @@ class IntelligentCommitAnalyzer {
144
162
  * Get groups that need attention (none - we don't verify)
145
163
  */
146
164
  getNeedsAttention(suggestions) {
165
+ const m_get_needs_attention = createMetricScope({
166
+ hook: 'intelligent_commit_analyzer',
167
+ operation: 'get_needs_attention'
168
+ });
169
+
170
+ m_get_needs_attention.started();
171
+ m_get_needs_attention.success();
147
172
  return [];
148
173
  }
149
174
  }
@@ -1,6 +1,10 @@
1
1
  const IntelligentCommitAnalyzer = require('./IntelligentCommitAnalyzer');
2
2
  const { getGitTreeState } = require('./GitTreeState');
3
3
 
4
+ const {
5
+ createMetricScope: createMetricScope
6
+ } = require('../../../infrastructure/telemetry/metric-scope');
7
+
4
8
  class IntelligentGitTreeMonitor {
5
9
  constructor({
6
10
  repoRoot = process.cwd(),
@@ -8,11 +12,18 @@ class IntelligentGitTreeMonitor {
8
12
  logger = console,
9
13
  autoCommitEnabled = false
10
14
  } = {}) {
15
+ const m_constructor = createMetricScope({
16
+ hook: 'intelligent_git_tree_monitor',
17
+ operation: 'constructor'
18
+ });
19
+
20
+ m_constructor.started();
11
21
  this.repoRoot = repoRoot;
12
22
  this.notifier = notifier;
13
23
  this.logger = logger;
14
24
  this.autoCommitEnabled = autoCommitEnabled;
15
25
  this.analyzer = new IntelligentCommitAnalyzer({ repoRoot, logger });
26
+ m_constructor.success();
16
27
  }
17
28
 
18
29
  /**
@@ -2,10 +2,21 @@ const path = require('path');
2
2
  const fs = require('fs');
3
3
  const PlatformHeuristics = require('./platform/PlatformHeuristics');
4
4
 
5
+ const {
6
+ createMetricScope: createMetricScope
7
+ } = require('../../../infrastructure/telemetry/metric-scope');
8
+
5
9
  class PlatformAnalysisService {
6
10
  constructor(platformDetector) {
11
+ const m_constructor = createMetricScope({
12
+ hook: 'platform_analysis_service',
13
+ operation: 'constructor'
14
+ });
15
+
16
+ m_constructor.started();
7
17
  this.platformDetector = platformDetector;
8
18
  this.heuristics = new PlatformHeuristics(platformDetector);
19
+ m_constructor.success();
9
20
  }
10
21
 
11
22
  /**
@@ -130,6 +141,12 @@ class PlatformAnalysisService {
130
141
  }
131
142
 
132
143
  getScoreReasons(platform, context) {
144
+ const m_get_score_reasons = createMetricScope({
145
+ hook: 'platform_analysis_service',
146
+ operation: 'get_score_reasons'
147
+ });
148
+
149
+ m_get_score_reasons.started();
133
150
  const reasons = [];
134
151
 
135
152
  if (context.stagedFiles && context.stagedFiles.length > 0) {
@@ -166,6 +183,8 @@ class PlatformAnalysisService {
166
183
  }
167
184
  }
168
185
 
186
+ m_get_score_reasons.success();
187
+
169
188
  return reasons;
170
189
  }
171
190
  }