pumuki-ast-hooks 5.3.18 → 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 (91) hide show
  1. package/docs/VIOLATIONS_RESOLUTION_PLAN.md +39 -37
  2. package/package.json +8 -2
  3. package/scripts/hooks-system/application/CompositionRoot.js +24 -73
  4. package/scripts/hooks-system/application/services/AutonomousOrchestrator.js +18 -0
  5. package/scripts/hooks-system/application/services/ContextDetectionEngine.js +58 -0
  6. package/scripts/hooks-system/application/services/DynamicRulesLoader.js +12 -2
  7. package/scripts/hooks-system/application/services/GitFlowService.js +80 -0
  8. package/scripts/hooks-system/application/services/GitTreeState.js +143 -13
  9. package/scripts/hooks-system/application/services/HookSystemScheduler.js +47 -0
  10. package/scripts/hooks-system/application/services/IntelligentCommitAnalyzer.js +25 -0
  11. package/scripts/hooks-system/application/services/IntelligentGitTreeMonitor.js +11 -0
  12. package/scripts/hooks-system/application/services/PlatformAnalysisService.js +19 -0
  13. package/scripts/hooks-system/application/services/PlatformDetectionService.js +19 -0
  14. package/scripts/hooks-system/application/services/PlaybookRunner.js +22 -1
  15. package/scripts/hooks-system/application/services/PredictiveHookAdvisor.js +19 -0
  16. package/scripts/hooks-system/application/services/RealtimeGuardPlugin.js +25 -0
  17. package/scripts/hooks-system/application/services/RealtimeGuardService.js +41 -84
  18. package/scripts/hooks-system/application/services/SmartDirtyTreeAnalyzer.js +11 -0
  19. package/scripts/hooks-system/application/services/commit/CommitMessageGenerator.js +11 -0
  20. package/scripts/hooks-system/application/services/commit/FeatureDetector.js +11 -0
  21. package/scripts/hooks-system/application/services/evidence/EvidenceContextManager.js +25 -0
  22. package/scripts/hooks-system/application/services/guard/GuardAutoManagerService.js +21 -31
  23. package/scripts/hooks-system/application/services/guard/GuardConfig.js +18 -15
  24. package/scripts/hooks-system/application/services/guard/GuardEventLogger.js +11 -0
  25. package/scripts/hooks-system/application/services/guard/GuardHealthReminder.js +26 -0
  26. package/scripts/hooks-system/application/services/guard/GuardHeartbeatMonitor.js +20 -6
  27. package/scripts/hooks-system/application/services/guard/GuardLockManager.js +11 -0
  28. package/scripts/hooks-system/application/services/guard/GuardMonitorLoop.js +25 -0
  29. package/scripts/hooks-system/application/services/guard/GuardNotificationHandler.js +11 -0
  30. package/scripts/hooks-system/application/services/guard/GuardProcessManager.js +10 -28
  31. package/scripts/hooks-system/application/services/guard/GuardRecoveryService.js +11 -0
  32. package/scripts/hooks-system/application/services/installation/ConfigurationGeneratorService.js +18 -0
  33. package/scripts/hooks-system/application/services/installation/FileSystemInstallerService.js +18 -0
  34. package/scripts/hooks-system/application/services/installation/GitEnvironmentService.js +18 -3
  35. package/scripts/hooks-system/application/services/installation/HookInstaller.js +19 -0
  36. package/scripts/hooks-system/application/services/installation/IdeIntegrationService.js +11 -0
  37. package/scripts/hooks-system/application/services/installation/InstallService.js +25 -1
  38. package/scripts/hooks-system/application/services/installation/McpConfigurator.js +19 -2
  39. package/scripts/hooks-system/application/services/installation/PlatformDetectorService.js +11 -0
  40. package/scripts/hooks-system/application/services/installation/VSCodeTaskConfigurator.js +11 -0
  41. package/scripts/hooks-system/application/services/logging/AuditLogger.js +90 -1
  42. package/scripts/hooks-system/application/services/logging/UnifiedLogger.js +15 -13
  43. package/scripts/hooks-system/application/services/monitoring/ActivityMonitor.js +33 -0
  44. package/scripts/hooks-system/application/services/monitoring/AstMonitor.js +27 -0
  45. package/scripts/hooks-system/application/services/monitoring/DevDocsMonitor.js +26 -0
  46. package/scripts/hooks-system/application/services/monitoring/EvidenceMonitor.js +19 -0
  47. package/scripts/hooks-system/application/services/monitoring/EvidenceMonitorService.js +27 -6
  48. package/scripts/hooks-system/application/services/monitoring/GitTreeMonitor.js +28 -0
  49. package/scripts/hooks-system/application/services/monitoring/GitTreeMonitorService.js +26 -0
  50. package/scripts/hooks-system/application/services/monitoring/HealthCheckProviders.js +4 -0
  51. package/scripts/hooks-system/application/services/monitoring/HealthCheckService.js +25 -0
  52. package/scripts/hooks-system/application/services/monitoring/HeartbeatMonitorService.js +26 -0
  53. package/scripts/hooks-system/application/services/monitoring/TokenMonitor.js +26 -0
  54. package/scripts/hooks-system/application/services/notification/MacNotificationSender.js +11 -0
  55. package/scripts/hooks-system/application/services/notification/NotificationCenterService.js +18 -0
  56. package/scripts/hooks-system/application/services/notification/NotificationDispatcher.js +11 -0
  57. package/scripts/hooks-system/application/services/notification/components/NotificationCooldownManager.js +18 -0
  58. package/scripts/hooks-system/application/services/notification/components/NotificationDeduplicator.js +18 -0
  59. package/scripts/hooks-system/application/services/notification/components/NotificationQueue.js +11 -0
  60. package/scripts/hooks-system/application/services/notification/components/NotificationRetryExecutor.js +20 -0
  61. package/scripts/hooks-system/application/services/platform/PlatformHeuristics.js +19 -0
  62. package/scripts/hooks-system/application/services/recovery/AutoRecoveryManager.js +19 -0
  63. package/scripts/hooks-system/application/services/smart-commit/CommitMessageSuggester.js +11 -0
  64. package/scripts/hooks-system/application/services/smart-commit/FileContextGrouper.js +19 -0
  65. package/scripts/hooks-system/application/services/smart-commit/SmartCommitSummaryBuilder.js +4 -0
  66. package/scripts/hooks-system/application/services/token/CursorTokenService.js +20 -0
  67. package/scripts/hooks-system/application/services/token/TokenMetricsService.js +11 -13
  68. package/scripts/hooks-system/application/services/token/TokenMonitorService.js +19 -0
  69. package/scripts/hooks-system/application/services/token/TokenStatusReporter.js +12 -0
  70. package/scripts/hooks-system/bin/__tests__/evidence-update.spec.js +49 -0
  71. package/scripts/hooks-system/bin/cli.js +1 -15
  72. package/scripts/hooks-system/config/project.config.json +1 -1
  73. package/scripts/hooks-system/domain/events/index.js +24 -31
  74. package/scripts/hooks-system/domain/exceptions/index.js +87 -0
  75. package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidAnalysisOrchestrator.js +2 -3
  76. package/scripts/hooks-system/infrastructure/ast/ast-core.js +20 -12
  77. package/scripts/hooks-system/infrastructure/ast/ast-intelligence.js +18 -8
  78. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/BackendPatternDetector.js +1 -2
  79. package/scripts/hooks-system/infrastructure/ast/backend/ast-backend.js +14 -18
  80. package/scripts/hooks-system/infrastructure/ast/frontend/ast-frontend.js +196 -196
  81. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSASTIntelligentAnalyzer.spec.js +66 -0
  82. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSASTIntelligentAnalyzer.js +2 -3
  83. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSArchitectureRules.js +24 -86
  84. package/scripts/hooks-system/infrastructure/config/config.js +5 -0
  85. package/scripts/hooks-system/infrastructure/hooks/skill-activation-prompt.js +2 -3
  86. package/scripts/hooks-system/infrastructure/logging/UnifiedLoggerFactory.js +5 -35
  87. package/scripts/hooks-system/infrastructure/orchestration/intelligent-audit.js +16 -86
  88. package/scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh +54 -92
  89. package/scripts/hooks-system/infrastructure/telemetry/metric-scope.js +98 -0
  90. package/scripts/hooks-system/infrastructure/telemetry/metrics-server.js +2 -51
  91. package/scripts/hooks-system/infrastructure/validators/enforce-english-literals.js +8 -6
@@ -31,15 +31,15 @@ elif [[ "$SCRIPT_DIR" == *"scripts/hooks-system"* ]]; then
31
31
  fi
32
32
  else
33
33
  # Fallback: try to find it relative to current directory
34
- REPO_ROOT="$(pwd)"
35
- if [[ -d "$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks" ]]; then
36
- HOOKS_SYSTEM_DIR="$REPO_ROOT/node_modules/@pumuki/ast-intelligence-hooks"
37
- elif [[ -d "$REPO_ROOT/scripts/hooks-system" ]]; then
38
- HOOKS_SYSTEM_DIR="$REPO_ROOT/scripts/hooks-system"
34
+ ROOT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
35
+ if [[ -d "$ROOT_DIR/node_modules/@pumuki/ast-intelligence-hooks" ]]; then
36
+ HOOKS_SYSTEM_DIR="$ROOT_DIR/node_modules/@pumuki/ast-intelligence-hooks"
37
+ elif [[ -d "$ROOT_DIR/scripts/hooks-system" ]]; then
38
+ HOOKS_SYSTEM_DIR="$ROOT_DIR/scripts/hooks-system"
39
39
  else
40
40
  echo "Error: Could not determine HOOKS_SYSTEM_DIR" >&2
41
41
  echo " SCRIPT_DIR: $SCRIPT_DIR" >&2
42
- echo " REPO_ROOT: $REPO_ROOT" >&2
42
+ echo " ROOT_DIR: $ROOT_DIR" >&2
43
43
  exit 1
44
44
  fi
45
45
  fi
@@ -58,11 +58,7 @@ source "$INFRASTRUCTURE_DIR/eslint/eslint-integration.sh"
58
58
  START_TIME=$(date +%s)
59
59
 
60
60
  # Determine repository root using git
61
- if command -v git >/dev/null 2>&1; then
62
- ROOT_DIR=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
63
- else
64
- ROOT_DIR=$(pwd)
65
- fi
61
+ ROOT_DIR=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
66
62
 
67
63
  # Default to temp directories to avoid polluting repositories.
68
64
  # Can be overridden by setting AUDIT_TMP / AUDIT_REPORTS.
@@ -212,6 +208,11 @@ run_intelligent_audit() {
212
208
  }
213
209
 
214
210
  full_audit() {
211
+ export AUDIT_STRICT=1
212
+ export BLOCK_ALL_SEVERITIES=1
213
+ export BLOCK_ON_REPO_VIOLATIONS=1
214
+ export AUDIT_LIBRARY=true
215
+ unset STAGING_ONLY_MODE
215
216
  run_basic_checks
216
217
  run_eslint_suite
217
218
  run_ast_intelligence
@@ -276,8 +277,8 @@ full_audit_strict_staging_only() {
276
277
  printf "\n%b✅ STAGING CLEAN - COMMIT ALLOWED%b\n" "$GREEN" "$NC"
277
278
  printf " 🔴 CRITICAL: 0\n"
278
279
  printf " 🟠 HIGH: 0\n"
279
- printf " 🟡 MEDIUM: 0\n"
280
- printf " 🔵 LOW: 0\n"
280
+ printf " 🟡 MEDIUM: %s\n" "$gate_med"
281
+ printf " 🔵 LOW: %s\n" "$gate_low"
281
282
  printf "\n All staged files pass strict quality gates.\n"
282
283
  printf " Ready to commit! 🚀\n\n"
283
284
  print_final_signature
@@ -544,8 +545,8 @@ summarize_all() {
544
545
  printf "\n%b2. ESLINT AUDIT RESULTS%b\n" "$YELLOW" "$NC"
545
546
  printf "─────────────────────────────────────────────────────────────\n"
546
547
  if [[ -f "$TMP_DIR/eslint-summary.txt" ]]; then
547
- es_err=$(grep -o 'errors=[0-9]\+' "$TMP_DIR/eslint-summary.txt" | head -n1 | sed 's/[^0-9]//g')
548
- es_warn=$(grep -o 'warnings=[0-9]\+' "$TMP_DIR/eslint-summary.txt" | head -n1 | sed 's/[^0-9]//g')
548
+ es_err=$(grep -o 'errors=[0-9]\+' "$TMP_DIR/eslint-summary.txt" 2>/dev/null | head -n1 | sed 's/[^0-9]//g')
549
+ es_warn=$(grep -o 'warnings=[0-9]\+' "$TMP_DIR/eslint-summary.txt" 2>/dev/null | head -n1 | sed 's/[^0-9]//g')
549
550
  es_err=${es_err:-0}; es_warn=${es_warn:-0}
550
551
  if [[ $es_err -gt 0 ]]; then
551
552
  printf " %bESLint:%b 🔴 errors=%s 🟡 warnings=%s\n" "$RED" "$NC" "$es_err" "$es_warn"
@@ -841,31 +842,32 @@ save_audit_reports() {
841
842
  local report_prefix="${REPORTS_DIR}/audit_${timestamp}"
842
843
 
843
844
  if [[ -f "$TMP_DIR/ast-summary.json" ]]; then
844
- cp "$TMP_DIR/ast-summary.json" "${report_prefix}_ast_summary.json"
845
+ mkdir -p "$ROOT_DIR/.audit-reports" || { echo "Failed to create .audit-reports directory"; exit 1; }
846
+ cp "$TMP_DIR/ast-summary.json" "$ROOT_DIR/.audit-reports/latest_ast-summary.json" || { echo "Failed to copy AST summary"; exit 1; }
845
847
  fi
846
848
 
847
849
  if [[ -f "$TMP_DIR/ast-findings.json" ]]; then
848
- cp "$TMP_DIR/ast-findings.json" "${report_prefix}_ast_findings.json"
850
+ cp "$TMP_DIR/ast-findings.json" "$REPORTS_DIR/latest_ast-findings.json"
849
851
  fi
850
852
 
851
853
  if [[ -f "$TMP_DIR/pattern-summary.txt" ]]; then
852
- cp "$TMP_DIR/pattern-summary.txt" "${report_prefix}_patterns.txt"
854
+ cp "$TMP_DIR/pattern-summary.txt" "$REPORTS_DIR/latest_patterns.txt"
853
855
  fi
854
856
 
855
857
  if [[ -f "$TMP_DIR/eslint-summary.txt" ]]; then
856
- cp "$TMP_DIR/eslint-summary.txt" "${report_prefix}_eslint.txt"
858
+ cp "$TMP_DIR/eslint-summary.txt" "$REPORTS_DIR/latest_eslint.txt"
857
859
  fi
858
860
 
859
- local latest_summary="${REPORTS_DIR}/latest_ast_summary.json"
860
- local latest_findings="${REPORTS_DIR}/latest_ast_findings.json"
861
- local latest_critical="${REPORTS_DIR}/latest_critical.json"
862
- local latest_high="${REPORTS_DIR}/latest_high.json"
863
- local latest_medium="${REPORTS_DIR}/latest_medium.json"
864
- local latest_low="${REPORTS_DIR}/latest_low.json"
861
+ local latest_summary="$REPORTS_DIR/latest_ast_summary.json"
862
+ local latest_findings="$REPORTS_DIR/latest_ast_findings.json"
863
+ local latest_critical="$REPORTS_DIR/latest_critical.json"
864
+ local latest_high="$REPORTS_DIR/latest_high.json"
865
+ local latest_medium="$REPORTS_DIR/latest_medium.json"
866
+ local latest_low="$REPORTS_DIR/latest_low.json"
865
867
 
866
868
  if [[ -f "$TMP_DIR/ast-summary.json" ]]; then
867
869
  cp "$TMP_DIR/ast-summary.json" "$latest_summary"
868
- cp "$TMP_DIR/ast-summary.json" "${REPORTS_DIR}/baseline_ast_summary.json"
870
+ cp "$TMP_DIR/ast-summary.json" "$REPORTS_DIR/baseline_ast_summary.json"
869
871
 
870
872
  if command -v jq >/dev/null 2>&1; then
871
873
  jq '{
@@ -923,15 +925,15 @@ save_audit_reports() {
923
925
  }
924
926
 
925
927
  export_markdown() {
926
- local out="${TMP_DIR}/audit-report.md"
928
+ local out="$TMP_DIR/audit-report.md"
927
929
  printf "# Audit Report\n\n" > "$out"
928
930
  printf "## %s\n\n" "$MSG_SUMMARY" >> "$out"
929
- if [[ -f "${TMP_DIR}/pattern-summary.txt" ]]; then
930
- cat "${TMP_DIR}/pattern-summary.txt" >> "$out"
931
+ if [[ -f "$TMP_DIR/pattern-summary.txt" ]]; then
932
+ cat "$TMP_DIR/pattern-summary.txt" >> "$out"
931
933
  printf "\n" >> "$out"
932
934
  fi
933
- if [[ -f "${TMP_DIR}/eslint-summary.txt" ]]; then
934
- cat "${TMP_DIR}/eslint-summary.txt" >> "$out"
935
+ if [[ -f "$TMP_DIR/eslint-summary.txt" ]]; then
936
+ cat "$TMP_DIR/eslint-summary.txt" >> "$out"
935
937
  printf "\n" >> "$out"
936
938
  fi
937
939
  printf "%s %s\n" "$EMJ_OK" "$out"
@@ -960,77 +962,33 @@ run_ast_intelligence() {
960
962
  if [[ -x "/usr/bin/node" ]]; then node_bin="/usr/bin/node"; fi
961
963
  fi
962
964
  if [[ -z "$node_bin" ]]; then
963
- local nvm_dir="${NVM_DIR:-$HOME/.nvm}"
964
- local nvm_default=""
965
- if [[ -f "$nvm_dir/alias/default" ]]; then
966
- nvm_default="$(cat "$nvm_dir/alias/default" 2>/dev/null || true)"
967
- nvm_default="${nvm_default##v}"
968
- nvm_default="${nvm_default%%[[:space:]]*}"
969
- fi
970
- if [[ -n "$nvm_default" ]] && [[ -x "$nvm_dir/versions/node/v${nvm_default}/bin/node" ]]; then
971
- node_bin="$nvm_dir/versions/node/v${nvm_default}/bin/node"
972
- fi
973
- fi
974
- if [[ -z "$node_bin" ]]; then
975
- local nvm_dir_fallback="${NVM_DIR:-$HOME/.nvm}"
976
- local latest_node=""
977
- latest_node="$(ls -1 "$nvm_dir_fallback/versions/node" 2>/dev/null | grep -E '^v[0-9]+' | sort -V | tail -n 1 || true)"
978
- if [[ -n "$latest_node" ]] && [[ -x "$nvm_dir_fallback/versions/node/${latest_node}/bin/node" ]]; then
979
- node_bin="$nvm_dir_fallback/versions/node/${latest_node}/bin/node"
980
- fi
981
- fi
982
- if [[ -z "$node_bin" ]]; then
983
- printf "%b❌ Node.js not found in PATH. Install Node.js >= 18 or ensure your shell loads nvm/asdf for non-interactive scripts.%b\n" "$RED" "$NC" >&2
984
- return 127
965
+ return 0
985
966
  fi
986
967
 
987
- # Determine NODE_PATH to include library's node_modules
988
- # Try multiple locations: HOOKS_SYSTEM_DIR/node_modules, or project root node_modules
989
- local -a node_path_parts
990
- node_path_parts=()
991
-
992
- # If HOOKS_SYSTEM_DIR has its own node_modules
993
- if [[ -d "$HOOKS_SYSTEM_DIR/node_modules" ]]; then
994
- node_path_parts+=("$HOOKS_SYSTEM_DIR/node_modules")
968
+ local intelligent_audit="$HOOKS_SYSTEM_DIR/infrastructure/orchestration/intelligent-audit.js"
969
+ if [[ ! -f "$intelligent_audit" ]]; then
970
+ return 0
995
971
  fi
996
-
997
- # Also check if we're in a project with node_modules/@pumuki/ast-intelligence-hooks
998
- local repo_root=""
999
- if [[ "$HOOKS_SYSTEM_DIR" == *"scripts/hooks-system"* ]]; then
1000
- # Running from scripts/hooks-system, go to repo root
1001
- repo_root="$(cd "$HOOKS_SYSTEM_DIR/../.." && pwd)"
1002
- elif [[ "$HOOKS_SYSTEM_DIR" == *"node_modules/@pumuki/ast-intelligence-hooks"* ]]; then
1003
- # Running from node_modules, go to repo root
1004
- repo_root="$(cd "$HOOKS_SYSTEM_DIR/../../.." && pwd)"
972
+
973
+ export AUDIT_TMP="$TMP_DIR"
974
+ if [[ "${BLOCK_ON_REPO_VIOLATIONS:-0}" == "1" ]]; then
975
+ export AI_GATE_SCOPE="repo"
1005
976
  else
1006
- # Try current directory
1007
- repo_root="$(pwd)"
1008
- fi
1009
-
1010
- if [[ -n "$repo_root" ]] && [[ -d "$repo_root/node_modules/@pumuki/ast-intelligence-hooks/node_modules" ]]; then
1011
- node_path_parts+=("$repo_root/node_modules/@pumuki/ast-intelligence-hooks/node_modules")
1012
- fi
1013
-
1014
- if [[ -n "$repo_root" ]] && [[ -d "$repo_root/node_modules" ]]; then
1015
- node_path_parts+=("$repo_root/node_modules")
977
+ export AI_GATE_SCOPE="staging"
1016
978
  fi
1017
979
 
1018
- # Build NODE_PATH
1019
980
  local node_path_value="${NODE_PATH:-}"
1020
- for path_part in "${node_path_parts[@]:-}"; do
1021
- if [[ -n "$node_path_value" ]]; then
1022
- node_path_value="$path_part:$node_path_value"
1023
- else
1024
- node_path_value="$path_part"
1025
- fi
1026
- done
981
+ if [[ -d "$HOOKS_SYSTEM_DIR/node_modules" ]]; then
982
+ node_path_value="$HOOKS_SYSTEM_DIR/node_modules${node_path_value:+:$node_path_value}"
983
+ fi
984
+ if [[ -d "$ROOT_DIR/node_modules" ]]; then
985
+ node_path_value="$ROOT_DIR/node_modules${node_path_value:+:$node_path_value}"
986
+ fi
1027
987
 
1028
- # Execute AST with proper error handling and NODE_PATH
1029
- # Change to HOOKS_SYSTEM_DIR so Node.js resolves modules correctly
1030
988
  if [[ -n "$node_path_value" ]]; then
1031
- ast_output=$(cd "$HOOKS_SYSTEM_DIR" && export NODE_PATH="$node_path_value" && export AUDIT_TMP="$TMP_DIR" && export AUDIT_LIBRARY="${AUDIT_LIBRARY:-false}" && "$node_bin" "${AST_DIR}/ast-intelligence.js" 2>&1) || ast_exit_code=$?
989
+ (cd "$ROOT_DIR" && export NODE_PATH="$node_path_value" && "$node_bin" "${AST_DIR}/ast-intelligence.js" 2>&1) || ast_exit_code=$?
1032
990
  else
1033
- ast_output=$(cd "$HOOKS_SYSTEM_DIR" && export AUDIT_TMP="$TMP_DIR" && export AUDIT_LIBRARY="${AUDIT_LIBRARY:-false}" && "$node_bin" "${AST_DIR}/ast-intelligence.js" 2>&1) || ast_exit_code=$?
991
+ (cd "$ROOT_DIR" && "$node_bin" "${AST_DIR}/ast-intelligence.js" 2>&1) || ast_exit_code=$?
1034
992
  fi
1035
993
 
1036
994
  # Check if AST script failed
@@ -1083,6 +1041,10 @@ run_ast_intelligence() {
1083
1041
  fi
1084
1042
 
1085
1043
  printf "%b✅ AST Intelligence completed%b\n\n" "$GREEN" "$NC"
1044
+
1045
+ # Ensure the .audit-reports directory exists and copy the AST summary
1046
+ mkdir -p "$ROOT_DIR/.audit-reports" || { echo "Failed to create .audit-reports directory"; exit 1; }
1047
+ cp "$TMP_DIR/ast-summary.json" "$ROOT_DIR/.audit-reports/latest_ast-summary.json" || { echo "Failed to copy AST summary"; exit 1; }
1086
1048
  }
1087
1049
 
1088
1050
  interactive_menu() {
@@ -0,0 +1,98 @@
1
+ const { recordMetric } = require('./metrics-logger');
2
+
3
+ function truncateString(value, maxLen) {
4
+ if (typeof value !== 'string') {
5
+ return value;
6
+ }
7
+ if (!Number.isFinite(maxLen) || maxLen <= 0) {
8
+ return value;
9
+ }
10
+ if (value.length <= maxLen) {
11
+ return value;
12
+ }
13
+ return value.substring(0, maxLen);
14
+ }
15
+
16
+ function sanitizeMeta(meta, { maxStringLength = 120 } = {}) {
17
+ if (!meta || typeof meta !== 'object') {
18
+ return {};
19
+ }
20
+
21
+ const out = {};
22
+ for (const [k, v] of Object.entries(meta)) {
23
+ if (v == null) {
24
+ continue;
25
+ }
26
+ if (typeof v === 'string') {
27
+ out[k] = truncateString(v, maxStringLength);
28
+ continue;
29
+ }
30
+ if (typeof v === 'number' || typeof v === 'boolean') {
31
+ out[k] = v;
32
+ continue;
33
+ }
34
+ if (v instanceof Error) {
35
+ out[k] = truncateString(v.message, maxStringLength);
36
+ continue;
37
+ }
38
+
39
+ try {
40
+ out[k] = JSON.parse(JSON.stringify(v));
41
+ } catch {
42
+ out[k] = truncateString(String(v), maxStringLength);
43
+ }
44
+ }
45
+ return out;
46
+ }
47
+
48
+ function toErrorMeta(error, { maxStringLength = 160 } = {}) {
49
+ if (!error) {
50
+ return {};
51
+ }
52
+
53
+ if (typeof error === 'string') {
54
+ return { error: truncateString(error, maxStringLength) };
55
+ }
56
+
57
+ const err = error instanceof Error ? error : null;
58
+ if (!err) {
59
+ return { error: truncateString(String(error), maxStringLength) };
60
+ }
61
+
62
+ return {
63
+ error: truncateString(err.message, maxStringLength),
64
+ errorName: truncateString(err.name, 80)
65
+ };
66
+ }
67
+
68
+ function createMetricScope({ hook, operation, baseMeta = {}, options = {} } = {}) {
69
+ const base = sanitizeMeta({ ...baseMeta }, options);
70
+
71
+ const startedAt = Date.now();
72
+
73
+ function emit(status, meta = {}) {
74
+ recordMetric({
75
+ hook,
76
+ operation,
77
+ status,
78
+ ...base,
79
+ ...sanitizeMeta(meta, options)
80
+ });
81
+ }
82
+
83
+ return {
84
+ started(meta = {}) {
85
+ emit('started', meta);
86
+ },
87
+ success(meta = {}) {
88
+ emit('success', { durationMs: Date.now() - startedAt, ...meta });
89
+ },
90
+ failed(error, meta = {}) {
91
+ emit('failed', { durationMs: Date.now() - startedAt, ...toErrorMeta(error, options), ...meta });
92
+ }
93
+ };
94
+ }
95
+
96
+ module.exports = {
97
+ createMetricScope
98
+ };
@@ -3,22 +3,9 @@
3
3
  const http = require('http');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
- const env = require('../../config/env');
7
6
 
8
- // AuditLogger import for logging critical operations
9
- const AuditLogger = require('../services/logging/AuditLogger');
10
-
11
- // Import recordMetric for prometheus metrics
12
- const { recordMetric } = require('./metrics-logger');
13
-
14
- const PORT = env.getNumber('HOOK_METRICS_PORT', 9464);
15
- const METRICS_FILE = path.join(process.cwd(), env.get('HOOK_METRICS_FILE', '.audit_tmp/hook-metrics.jsonl'));
16
-
17
- // Initialize audit logger
18
- const auditLogger = new AuditLogger({
19
- repoRoot: process.cwd(),
20
- filename: path.join('.audit_tmp', 'metrics-server-audit.log')
21
- });
7
+ const PORT = Number(process.env.HOOK_METRICS_PORT || 9464);
8
+ const METRICS_FILE = path.join(process.cwd(), '.audit_tmp', 'hook-metrics.jsonl');
22
9
 
23
10
  function loadMetrics() {
24
11
  if (!fs.existsSync(METRICS_FILE)) return [];
@@ -62,49 +49,13 @@ const server = http.createServer((req, res) => {
62
49
  const body = buildPrometheusMetrics();
63
50
  res.writeHead(200, { 'Content-Type': 'text/plain' });
64
51
  res.end(body);
65
-
66
- auditLogger.log({
67
- action: 'metrics_served',
68
- category: 'observability',
69
- severity: 'info',
70
- message: 'Prometheus metrics served successfully',
71
- metadata: {
72
- port: PORT,
73
- metricsCount: body.split('\n').filter(line => line.trim() && !line.startsWith('#')).length,
74
- endpoint: '/metrics'
75
- }
76
- });
77
52
  return;
78
53
  }
79
54
 
80
55
  res.writeHead(404);
81
56
  res.end();
82
-
83
- auditLogger.log({
84
- action: 'invalid_request',
85
- category: 'observability',
86
- severity: 'warn',
87
- message: 'Invalid request to metrics server',
88
- metadata: {
89
- url: req.url,
90
- method: req.method,
91
- port: PORT
92
- }
93
- });
94
57
  });
95
58
 
96
59
  server.listen(PORT, () => {
97
60
  console.log(`Hook-System metrics server running on http://localhost:${PORT}/metrics`);
98
-
99
- auditLogger.log({
100
- action: 'server_started',
101
- category: 'system',
102
- severity: 'info',
103
- message: 'Metrics server started successfully',
104
- metadata: {
105
- port: PORT,
106
- endpoint: '/metrics',
107
- metricsFile: METRICS_FILE
108
- }
109
- });
110
61
  });
@@ -4,9 +4,8 @@
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
  const { execSync } = require('child_process');
7
- const env = require('../../config/env');
8
7
 
9
- const REPO_ROOT = env.get('HOOK_GUARD_REPO_ROOT', process.cwd());
8
+ const REPO_ROOT = process.env.HOOK_GUARD_REPO_ROOT || process.cwd();
10
9
  const CONFIG_PATH = path.join(REPO_ROOT, 'scripts', 'hooks-system', 'config', 'language-guard.json');
11
10
  const DEFAULT_IGNORED_SEGMENTS = [
12
11
  `${path.sep}node_modules${path.sep}`,
@@ -23,7 +22,7 @@ function decodeUnicode(value) {
23
22
  try {
24
23
  return JSON.parse(`"${value}"`);
25
24
  } catch (error) {
26
- if (env.isDev || env.getBool('DEBUG', false)) {
25
+ if (process.env.NODE_ENV === 'development' || process.env.DEBUG) {
27
26
  console.debug(`[enforce-english-literals] Failed to decode Unicode value "${value}": ${error.message}`);
28
27
  }
29
28
  return value;
@@ -120,10 +119,13 @@ function analyzeFile(relativePath, config) {
120
119
 
121
120
  function collectStagedFiles() {
122
121
  try {
123
- const stagedFilesRaw = execSync('git diff --cached --name-only', { encoding: 'utf8' });
124
- return stagedFilesRaw.split('\n').filter(Boolean).map(file => file.trim());
122
+ const raw = execSync('git diff --cached --name-only --diff-filter=ACMR', {
123
+ cwd: REPO_ROOT,
124
+ encoding: 'utf8'
125
+ });
126
+ return raw.split('\n').map(entry => entry.trim()).filter(Boolean);
125
127
  } catch (error) {
126
- if (env.isDev || env.getBool('DEBUG', false)) {
128
+ if (process.env.NODE_ENV === 'development' || process.env.DEBUG) {
127
129
  console.debug(`[enforce-english-literals] Failed to collect staged files: ${error.message}`);
128
130
  }
129
131
  return [];