pumuki-ast-hooks 5.3.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.
Files changed (567) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1105 -0
  3. package/bin/__tests__/auto-fix-violations.spec.js +132 -0
  4. package/bin/__tests__/auto-restart-guards.spec.js +11 -0
  5. package/bin/__tests__/check-doc-drift.spec.js +11 -0
  6. package/bin/__tests__/check-version.spec.js +240 -0
  7. package/bin/__tests__/cli.spec.js +11 -0
  8. package/bin/__tests__/guard-auto-manager.spec.js +11 -0
  9. package/bin/__tests__/guard-supervisor.spec.js +11 -0
  10. package/bin/__tests__/hook-status.spec.js +11 -0
  11. package/bin/__tests__/install.spec.js +11 -0
  12. package/bin/__tests__/nightly-metrics-report.spec.js +94 -0
  13. package/bin/__tests__/plan-review.spec.js +11 -0
  14. package/bin/__tests__/predictive-hooks.spec.js +11 -0
  15. package/bin/__tests__/run-ast-adapter.spec.js +11 -0
  16. package/bin/__tests__/run-orchestrator.spec.js +11 -0
  17. package/bin/__tests__/run-playbook.spec.js +11 -0
  18. package/bin/__tests__/setup-eslint.spec.js +11 -0
  19. package/bin/__tests__/violations-api.spec.js +11 -0
  20. package/bin/__tests__/watch-hooks.spec.js +11 -0
  21. package/bin/ai-commit.sh +5 -0
  22. package/bin/audit +5 -0
  23. package/bin/audit-library.js +6 -0
  24. package/bin/auto-fix-violations.js +19 -0
  25. package/bin/auto-restart-guards.js +6 -0
  26. package/bin/check-doc-drift.js +6 -0
  27. package/bin/check-version.js +19 -0
  28. package/bin/cleanup-branches.sh +5 -0
  29. package/bin/cli.js +6 -0
  30. package/bin/demo-recording.sh +5 -0
  31. package/bin/demo-violations +5 -0
  32. package/bin/fix-enforcer +5 -0
  33. package/bin/fix-gitflow-enforcement.sh +5 -0
  34. package/bin/generate-progress-report.sh +5 -0
  35. package/bin/git-analyze-pairs.sh +5 -0
  36. package/bin/git-leave-branch-check.sh +5 -0
  37. package/bin/gitflow +5 -0
  38. package/bin/gitflow-shell-integration.sh +5 -0
  39. package/bin/guard-auto-manager.js +6 -0
  40. package/bin/guard-autostart.sh +5 -0
  41. package/bin/guard-env.sh +5 -0
  42. package/bin/guard-supervisor.js +6 -0
  43. package/bin/hook-status.js +6 -0
  44. package/bin/install-git-wrapper.sh +5 -0
  45. package/bin/install.js +6 -0
  46. package/bin/kill-mcp-zombies.sh +5 -0
  47. package/bin/nightly-metrics-report.js +8 -0
  48. package/bin/plan-review.js +6 -0
  49. package/bin/predictive-hooks.js +6 -0
  50. package/bin/pumuki-audit.js +6 -0
  51. package/bin/pumuki-init.js +19 -0
  52. package/bin/pumuki-mcp-server.js +13 -0
  53. package/bin/pumuki-mcp.js +6 -0
  54. package/bin/pumuki-rules.js +6 -0
  55. package/bin/request-no-verify-approval.sh +5 -0
  56. package/bin/run-ast-adapter.js +6 -0
  57. package/bin/run-intelligent-audit.sh +5 -0
  58. package/bin/run-orchestrator.js +6 -0
  59. package/bin/run-playbook.js +6 -0
  60. package/bin/session-loader.sh +5 -0
  61. package/bin/setup-eslint.js +6 -0
  62. package/bin/start-guards.sh +5 -0
  63. package/bin/sync-autonomous-orchestrator.sh +5 -0
  64. package/bin/sync-to-library.sh +5 -0
  65. package/bin/update-evidence.sh +5 -0
  66. package/bin/update-session-context.sh +5 -0
  67. package/bin/verify-no-verify.sh +5 -0
  68. package/bin/violations +5 -0
  69. package/bin/violations-api.js +6 -0
  70. package/bin/watch-hooks.js +6 -0
  71. package/docs/API_REFERENCE.md +161 -0
  72. package/docs/ARCHITECTURE.md +236 -0
  73. package/docs/ARCHITECTURE_DETAILED.md +499 -0
  74. package/docs/BRANCH_PROTECTION_GUIDE.md +236 -0
  75. package/docs/CODE_STANDARDS.md +440 -0
  76. package/docs/CONTRIBUTING.md +246 -0
  77. package/docs/DEPENDENCIES.md +541 -0
  78. package/docs/HOW_IT_WORKS.md +716 -0
  79. package/docs/INSTALLATION.md +784 -0
  80. package/docs/MCP_SERVERS.md +786 -0
  81. package/docs/TESTING.md +423 -0
  82. package/docs/USAGE.md +856 -0
  83. package/docs/images/ast_intelligence_01.png +0 -0
  84. package/docs/images/ast_intelligence_02.png +0 -0
  85. package/docs/images/ast_intelligence_03.png +0 -0
  86. package/docs/images/ast_intelligence_04.png +0 -0
  87. package/docs/images/ast_intelligence_05.png +0 -0
  88. package/hooks/getSkillRulesPath.ts +52 -0
  89. package/hooks/git-status-monitor.ts +160 -0
  90. package/hooks/index.js +5 -0
  91. package/hooks/notify-macos.ts +42 -0
  92. package/hooks/package.json +16 -0
  93. package/hooks/post-tool-use-tracker.sh +89 -0
  94. package/hooks/pre-tool-use-evidence-validator.ts +252 -0
  95. package/hooks/pre-tool-use-guard.ts +151 -0
  96. package/hooks/skill-activation-prompt.sh +8 -0
  97. package/hooks/skill-activation-prompt.ts +307 -0
  98. package/index.js +49 -0
  99. package/package.json +117 -0
  100. package/presentation/cli/audit.sh +24 -0
  101. package/presentation/cli/autonomous-status.sh +92 -0
  102. package/presentation/cli/categorize-violations.sh +179 -0
  103. package/presentation/cli/direct-audit-option2.sh +23 -0
  104. package/presentation/cli/direct-audit.sh +33 -0
  105. package/scripts/hooks-system/.AI_TOKEN_STATUS.txt +16 -0
  106. package/scripts/hooks-system/.audit-reports/auto-recovery.log +1 -0
  107. package/scripts/hooks-system/.audit-reports/install-wizard.log +4 -0
  108. package/scripts/hooks-system/.audit-reports/notifications.log +425 -0
  109. package/scripts/hooks-system/.audit-reports/token-monitor.log +1275 -0
  110. package/scripts/hooks-system/.audit_tmp/intelligent-report.json +44953 -0
  111. package/scripts/hooks-system/.audit_tmp/intelligent-report.txt +1338 -0
  112. package/scripts/hooks-system/.audit_tmp/severity-history.jsonl +1 -0
  113. package/scripts/hooks-system/.audit_tmp/token-usage.jsonl +1 -0
  114. package/scripts/hooks-system/.hook-system/config.json +8 -0
  115. package/scripts/hooks-system/application/CompositionRoot.js +325 -0
  116. package/scripts/hooks-system/application/__tests__/CompositionRoot.spec.js +84 -0
  117. package/scripts/hooks-system/application/commands/index.js +64 -0
  118. package/scripts/hooks-system/application/queries/index.js +60 -0
  119. package/scripts/hooks-system/application/services/AutonomousOrchestrator.js +130 -0
  120. package/scripts/hooks-system/application/services/ContextDetectionEngine.js +181 -0
  121. package/scripts/hooks-system/application/services/DynamicRulesLoader.js +182 -0
  122. package/scripts/hooks-system/application/services/GitFlowService.js +156 -0
  123. package/scripts/hooks-system/application/services/GitTreeState.js +140 -0
  124. package/scripts/hooks-system/application/services/HookSystemScheduler.js +77 -0
  125. package/scripts/hooks-system/application/services/IntelligentCommitAnalyzer.js +151 -0
  126. package/scripts/hooks-system/application/services/IntelligentGitTreeMonitor.js +118 -0
  127. package/scripts/hooks-system/application/services/PlatformAnalysisService.js +173 -0
  128. package/scripts/hooks-system/application/services/PlatformDetectionService.js +168 -0
  129. package/scripts/hooks-system/application/services/PlaybookRunner.js +39 -0
  130. package/scripts/hooks-system/application/services/PredictiveHookAdvisor.js +56 -0
  131. package/scripts/hooks-system/application/services/RealtimeGuardPlugin.js +62 -0
  132. package/scripts/hooks-system/application/services/RealtimeGuardService.js +374 -0
  133. package/scripts/hooks-system/application/services/SmartDirtyTreeAnalyzer.js +63 -0
  134. package/scripts/hooks-system/application/services/__tests__/AutonomousOrchestrator.spec.js +36 -0
  135. package/scripts/hooks-system/application/services/__tests__/ContextDetectionEngine.spec.js +33 -0
  136. package/scripts/hooks-system/application/services/__tests__/DynamicRulesLoader.spec.js +43 -0
  137. package/scripts/hooks-system/application/services/__tests__/GitTreeState.spec.js +163 -0
  138. package/scripts/hooks-system/application/services/__tests__/HookSystemScheduler.spec.js +207 -0
  139. package/scripts/hooks-system/application/services/__tests__/IntelligentCommitAnalyzer.spec.js +365 -0
  140. package/scripts/hooks-system/application/services/__tests__/IntelligentGitTreeMonitor.spec.js +188 -0
  141. package/scripts/hooks-system/application/services/__tests__/PlatformDetectionService.spec.js +28 -0
  142. package/scripts/hooks-system/application/services/__tests__/PlaybookRunner.spec.js +143 -0
  143. package/scripts/hooks-system/application/services/__tests__/PredictiveHookAdvisor.spec.js +181 -0
  144. package/scripts/hooks-system/application/services/__tests__/RealtimeGuardPlugin.spec.js +45 -0
  145. package/scripts/hooks-system/application/services/__tests__/RealtimeGuardService.critical.spec.js +401 -0
  146. package/scripts/hooks-system/application/services/commit/CommitMessageGenerator.js +34 -0
  147. package/scripts/hooks-system/application/services/commit/FeatureDetector.js +101 -0
  148. package/scripts/hooks-system/application/services/evidence/EvidenceContextManager.js +163 -0
  149. package/scripts/hooks-system/application/services/evidence/__tests__/EvidenceContextManager.spec.js +98 -0
  150. package/scripts/hooks-system/application/services/guard/GuardAutoManagerService.js +169 -0
  151. package/scripts/hooks-system/application/services/guard/GuardConfig.js +15 -0
  152. package/scripts/hooks-system/application/services/guard/GuardEventLogger.js +70 -0
  153. package/scripts/hooks-system/application/services/guard/GuardHealthReminder.js +54 -0
  154. package/scripts/hooks-system/application/services/guard/GuardHeartbeatMonitor.js +94 -0
  155. package/scripts/hooks-system/application/services/guard/GuardLockManager.js +72 -0
  156. package/scripts/hooks-system/application/services/guard/GuardMonitorLoop.js +29 -0
  157. package/scripts/hooks-system/application/services/guard/GuardNotificationHandler.js +36 -0
  158. package/scripts/hooks-system/application/services/guard/GuardProcessManager.js +113 -0
  159. package/scripts/hooks-system/application/services/guard/GuardRecoveryService.js +90 -0
  160. package/scripts/hooks-system/application/services/guard/__tests__/GuardAutoManagerService.spec.js +77 -0
  161. package/scripts/hooks-system/application/services/installation/ConfigurationGeneratorService.js +123 -0
  162. package/scripts/hooks-system/application/services/installation/FileSystemInstallerService.js +112 -0
  163. package/scripts/hooks-system/application/services/installation/GitEnvironmentService.js +166 -0
  164. package/scripts/hooks-system/application/services/installation/HookInstaller.js +197 -0
  165. package/scripts/hooks-system/application/services/installation/IdeIntegrationService.js +37 -0
  166. package/scripts/hooks-system/application/services/installation/InstallService.js +130 -0
  167. package/scripts/hooks-system/application/services/installation/McpConfigurator.js +172 -0
  168. package/scripts/hooks-system/application/services/installation/PlatformDetectorService.js +36 -0
  169. package/scripts/hooks-system/application/services/installation/VSCodeTaskConfigurator.js +97 -0
  170. package/scripts/hooks-system/application/services/logging/UnifiedLogger.js +142 -0
  171. package/scripts/hooks-system/application/services/logging/__tests__/UnifiedLogger.spec.js +66 -0
  172. package/scripts/hooks-system/application/services/monitoring/ActivityMonitor.js +80 -0
  173. package/scripts/hooks-system/application/services/monitoring/AstMonitor.js +140 -0
  174. package/scripts/hooks-system/application/services/monitoring/DevDocsMonitor.js +85 -0
  175. package/scripts/hooks-system/application/services/monitoring/EvidenceMonitor.js +103 -0
  176. package/scripts/hooks-system/application/services/monitoring/EvidenceMonitorService.js +162 -0
  177. package/scripts/hooks-system/application/services/monitoring/GitTreeMonitor.js +123 -0
  178. package/scripts/hooks-system/application/services/monitoring/GitTreeMonitorService.js +114 -0
  179. package/scripts/hooks-system/application/services/monitoring/HealthCheckProviders.js +153 -0
  180. package/scripts/hooks-system/application/services/monitoring/HealthCheckService.js +118 -0
  181. package/scripts/hooks-system/application/services/monitoring/HeartbeatMonitorService.js +61 -0
  182. package/scripts/hooks-system/application/services/monitoring/TokenMonitor.js +60 -0
  183. package/scripts/hooks-system/application/services/monitoring/__tests__/EvidenceMonitorService.spec.js +107 -0
  184. package/scripts/hooks-system/application/services/monitoring/__tests__/GitTreeMonitorService.spec.js +27 -0
  185. package/scripts/hooks-system/application/services/monitoring/__tests__/HealthCheckProviders.spec.js +68 -0
  186. package/scripts/hooks-system/application/services/monitoring/__tests__/HealthCheckService.spec.js +69 -0
  187. package/scripts/hooks-system/application/services/monitoring/__tests__/HeartbeatMonitorService.spec.js +35 -0
  188. package/scripts/hooks-system/application/services/notification/MacNotificationSender.js +106 -0
  189. package/scripts/hooks-system/application/services/notification/NotificationCenterService.js +221 -0
  190. package/scripts/hooks-system/application/services/notification/NotificationDispatcher.js +42 -0
  191. package/scripts/hooks-system/application/services/notification/__tests__/NotificationCenterService.spec.js +40 -0
  192. package/scripts/hooks-system/application/services/notification/components/NotificationCooldownManager.js +62 -0
  193. package/scripts/hooks-system/application/services/notification/components/NotificationDeduplicator.js +67 -0
  194. package/scripts/hooks-system/application/services/notification/components/NotificationQueue.js +36 -0
  195. package/scripts/hooks-system/application/services/notification/components/NotificationRetryExecutor.js +58 -0
  196. package/scripts/hooks-system/application/services/platform/PlatformHeuristics.js +144 -0
  197. package/scripts/hooks-system/application/services/recovery/AutoRecoveryManager.js +137 -0
  198. package/scripts/hooks-system/application/services/recovery/__tests__/AutoRecoveryManager.spec.js +62 -0
  199. package/scripts/hooks-system/application/services/smart-commit/CommitMessageSuggester.js +97 -0
  200. package/scripts/hooks-system/application/services/smart-commit/FileContextGrouper.js +114 -0
  201. package/scripts/hooks-system/application/services/smart-commit/SmartCommitSummaryBuilder.js +53 -0
  202. package/scripts/hooks-system/application/services/token/CursorTokenService.js +44 -0
  203. package/scripts/hooks-system/application/services/token/TokenMetricsService.js +109 -0
  204. package/scripts/hooks-system/application/services/token/TokenMonitorService.js +160 -0
  205. package/scripts/hooks-system/application/services/token/TokenStatusReporter.js +56 -0
  206. package/scripts/hooks-system/application/services/token/__tests__/CursorTokenService.spec.js +69 -0
  207. package/scripts/hooks-system/application/services/token/__tests__/TokenMonitorService.spec.js +185 -0
  208. package/scripts/hooks-system/application/state/HookSystemStateMachine.js +59 -0
  209. package/scripts/hooks-system/application/state/__tests__/HookSystemStateMachine.spec.js +115 -0
  210. package/scripts/hooks-system/application/use-cases/AnalyzeCodebaseUseCase.js +54 -0
  211. package/scripts/hooks-system/application/use-cases/AnalyzeStagedFilesUseCase.js +61 -0
  212. package/scripts/hooks-system/application/use-cases/AutoExecuteAIStartUseCase.js +123 -0
  213. package/scripts/hooks-system/application/use-cases/BlockCommitUseCase.js +90 -0
  214. package/scripts/hooks-system/application/use-cases/GenerateAuditReportUseCase.js +184 -0
  215. package/scripts/hooks-system/application/use-cases/__tests__/AnalyzeCodebaseUseCase.spec.js +156 -0
  216. package/scripts/hooks-system/application/use-cases/__tests__/AnalyzeStagedFilesUseCase.spec.js +146 -0
  217. package/scripts/hooks-system/application/use-cases/__tests__/AutoExecuteAIStartUseCase.spec.js +89 -0
  218. package/scripts/hooks-system/application/use-cases/__tests__/BlockCommitUseCase.spec.js +171 -0
  219. package/scripts/hooks-system/application/use-cases/__tests__/GenerateAuditReportUseCase.spec.js +207 -0
  220. package/scripts/hooks-system/bin/__tests__/auto-fix-violations.spec.js +132 -0
  221. package/scripts/hooks-system/bin/__tests__/auto-restart-guards.spec.js +11 -0
  222. package/scripts/hooks-system/bin/__tests__/check-doc-drift.spec.js +11 -0
  223. package/scripts/hooks-system/bin/__tests__/check-version.spec.js +240 -0
  224. package/scripts/hooks-system/bin/__tests__/cli.spec.js +11 -0
  225. package/scripts/hooks-system/bin/__tests__/guard-auto-manager.spec.js +11 -0
  226. package/scripts/hooks-system/bin/__tests__/guard-supervisor.spec.js +11 -0
  227. package/scripts/hooks-system/bin/__tests__/hook-status.spec.js +11 -0
  228. package/scripts/hooks-system/bin/__tests__/install.spec.js +11 -0
  229. package/scripts/hooks-system/bin/__tests__/nightly-metrics-report.spec.js +94 -0
  230. package/scripts/hooks-system/bin/__tests__/plan-review.spec.js +11 -0
  231. package/scripts/hooks-system/bin/__tests__/predictive-hooks.spec.js +11 -0
  232. package/scripts/hooks-system/bin/__tests__/run-ast-adapter.spec.js +11 -0
  233. package/scripts/hooks-system/bin/__tests__/run-orchestrator.spec.js +11 -0
  234. package/scripts/hooks-system/bin/__tests__/run-playbook.spec.js +11 -0
  235. package/scripts/hooks-system/bin/__tests__/setup-eslint.spec.js +11 -0
  236. package/scripts/hooks-system/bin/__tests__/violations-api.spec.js +11 -0
  237. package/scripts/hooks-system/bin/__tests__/watch-hooks.spec.js +11 -0
  238. package/scripts/hooks-system/bin/ai-commit.sh +63 -0
  239. package/scripts/hooks-system/bin/audit +463 -0
  240. package/scripts/hooks-system/bin/audit-library.js +54 -0
  241. package/scripts/hooks-system/bin/auto-fix-violations.js +130 -0
  242. package/scripts/hooks-system/bin/auto-restart-guards.js +93 -0
  243. package/scripts/hooks-system/bin/check-doc-drift.js +35 -0
  244. package/scripts/hooks-system/bin/check-version.js +201 -0
  245. package/scripts/hooks-system/bin/cleanup-branches.sh +106 -0
  246. package/scripts/hooks-system/bin/cli.js +208 -0
  247. package/scripts/hooks-system/bin/demo-recording.sh +57 -0
  248. package/scripts/hooks-system/bin/demo-violations +44 -0
  249. package/scripts/hooks-system/bin/fix-enforcer +27 -0
  250. package/scripts/hooks-system/bin/fix-gitflow-enforcement.sh +68 -0
  251. package/scripts/hooks-system/bin/generate-progress-report.sh +129 -0
  252. package/scripts/hooks-system/bin/git-analyze-pairs.sh +0 -0
  253. package/scripts/hooks-system/bin/git-leave-branch-check.sh +73 -0
  254. package/scripts/hooks-system/bin/gitflow +17 -0
  255. package/scripts/hooks-system/bin/gitflow-shell-integration.sh +64 -0
  256. package/scripts/hooks-system/bin/guard-auto-manager.js +44 -0
  257. package/scripts/hooks-system/bin/guard-autostart.sh +158 -0
  258. package/scripts/hooks-system/bin/guard-env.sh +40 -0
  259. package/scripts/hooks-system/bin/guard-supervisor.js +516 -0
  260. package/scripts/hooks-system/bin/hook-status.js +41 -0
  261. package/scripts/hooks-system/bin/install-git-wrapper.sh +53 -0
  262. package/scripts/hooks-system/bin/install.js +10 -0
  263. package/scripts/hooks-system/bin/kill-mcp-zombies.sh +48 -0
  264. package/scripts/hooks-system/bin/nightly-metrics-report.js +138 -0
  265. package/scripts/hooks-system/bin/plan-review.js +31 -0
  266. package/scripts/hooks-system/bin/predictive-hooks.js +18 -0
  267. package/scripts/hooks-system/bin/pumuki-audit.js +113 -0
  268. package/scripts/hooks-system/bin/pumuki-init.js +104 -0
  269. package/scripts/hooks-system/bin/pumuki-mcp.js +74 -0
  270. package/scripts/hooks-system/bin/pumuki-rules.js +74 -0
  271. package/scripts/hooks-system/bin/request-no-verify-approval.sh +116 -0
  272. package/scripts/hooks-system/bin/run-ast-adapter.js +86 -0
  273. package/scripts/hooks-system/bin/run-intelligent-audit.sh +67 -0
  274. package/scripts/hooks-system/bin/run-orchestrator.js +27 -0
  275. package/scripts/hooks-system/bin/run-playbook.js +23 -0
  276. package/scripts/hooks-system/bin/session-loader.sh +264 -0
  277. package/scripts/hooks-system/bin/setup-eslint.js +110 -0
  278. package/scripts/hooks-system/bin/start-guards.sh +190 -0
  279. package/scripts/hooks-system/bin/sync-autonomous-orchestrator.sh +32 -0
  280. package/scripts/hooks-system/bin/sync-to-library.sh +46 -0
  281. package/scripts/hooks-system/bin/update-evidence.sh +1167 -0
  282. package/scripts/hooks-system/bin/update-session-context.sh +261 -0
  283. package/scripts/hooks-system/bin/verify-no-verify.sh +68 -0
  284. package/scripts/hooks-system/bin/violations +20 -0
  285. package/scripts/hooks-system/bin/violations-api.js +345 -0
  286. package/scripts/hooks-system/bin/watch-hooks.js +20 -0
  287. package/scripts/hooks-system/config/project.config.json +36 -0
  288. package/scripts/hooks-system/config/state-map.json +12 -0
  289. package/scripts/hooks-system/domain/entities/AuditResult.js +139 -0
  290. package/scripts/hooks-system/domain/entities/Finding.js +116 -0
  291. package/scripts/hooks-system/domain/entities/SeverityConfig.js +73 -0
  292. package/scripts/hooks-system/domain/entities/SeverityConfig.ts +90 -0
  293. package/scripts/hooks-system/domain/entities/__tests__/AuditResult.spec.js +450 -0
  294. package/scripts/hooks-system/domain/entities/__tests__/Finding.spec.js +335 -0
  295. package/scripts/hooks-system/domain/entities/__tests__/SeverityConfig.spec.js +240 -0
  296. package/scripts/hooks-system/domain/entities/__tests__/entities.spec.js +29 -0
  297. package/scripts/hooks-system/domain/errors/__tests__/DomainErrors.spec.js +59 -0
  298. package/scripts/hooks-system/domain/errors/index.js +169 -0
  299. package/scripts/hooks-system/domain/events/__tests__/DomainEvents.spec.js +60 -0
  300. package/scripts/hooks-system/domain/events/index.js +121 -0
  301. package/scripts/hooks-system/domain/ports/IAstPort.js +67 -0
  302. package/scripts/hooks-system/domain/ports/IEvidencePort.js +86 -0
  303. package/scripts/hooks-system/domain/ports/IGitCommandPort.js +110 -0
  304. package/scripts/hooks-system/domain/ports/IGitPort.js +114 -0
  305. package/scripts/hooks-system/domain/ports/IGitQueryPort.js +93 -0
  306. package/scripts/hooks-system/domain/ports/INotificationPort.js +35 -0
  307. package/scripts/hooks-system/domain/ports/__tests__/ports.spec.js +36 -0
  308. package/scripts/hooks-system/domain/ports/index.js +14 -0
  309. package/scripts/hooks-system/domain/repositories/ICursorTokenRepository.js +13 -0
  310. package/scripts/hooks-system/domain/repositories/IFindingsRepository.js +30 -0
  311. package/scripts/hooks-system/domain/repositories/__tests__/IFindingsRepository.spec.js +18 -0
  312. package/scripts/hooks-system/domain/rules/CommitBlockingRules.js +142 -0
  313. package/scripts/hooks-system/domain/rules/__tests__/CommitBlockingRules.spec.js +18 -0
  314. package/scripts/hooks-system/domain/services/AuditAnalyzer.js +103 -0
  315. package/scripts/hooks-system/domain/services/AuditFilter.js +26 -0
  316. package/scripts/hooks-system/domain/services/AuditResultSerializer.js +35 -0
  317. package/scripts/hooks-system/domain/services/AuditScorer.js +38 -0
  318. package/scripts/hooks-system/domain/values/Severity.js +93 -0
  319. package/scripts/hooks-system/index.js +49 -0
  320. package/scripts/hooks-system/infrastructure/adapters/AstAnalyzerAdapter.js +150 -0
  321. package/scripts/hooks-system/infrastructure/adapters/FileEvidenceAdapter.js +140 -0
  322. package/scripts/hooks-system/infrastructure/adapters/GitCliAdapter.js +16 -0
  323. package/scripts/hooks-system/infrastructure/adapters/GitCommandAdapter.js +68 -0
  324. package/scripts/hooks-system/infrastructure/adapters/GitHubCliAdapter.js +85 -0
  325. package/scripts/hooks-system/infrastructure/adapters/GitQueryAdapter.js +58 -0
  326. package/scripts/hooks-system/infrastructure/adapters/LegacyAnalyzerAdapter.js +61 -0
  327. package/scripts/hooks-system/infrastructure/adapters/MacOSNotificationAdapter.js +99 -0
  328. package/scripts/hooks-system/infrastructure/adapters/__tests__/AstAnalyzerAdapter.spec.js +32 -0
  329. package/scripts/hooks-system/infrastructure/adapters/__tests__/FileEvidenceAdapter.spec.js +31 -0
  330. package/scripts/hooks-system/infrastructure/adapters/__tests__/GitCliAdapter.spec.js +39 -0
  331. package/scripts/hooks-system/infrastructure/adapters/__tests__/MacOSNotificationAdapter.spec.js +33 -0
  332. package/scripts/hooks-system/infrastructure/adapters/git/GitCommandRunner.js +78 -0
  333. package/scripts/hooks-system/infrastructure/adapters/git/GitCommandService.js +67 -0
  334. package/scripts/hooks-system/infrastructure/adapters/git/GitQueryService.js +50 -0
  335. package/scripts/hooks-system/infrastructure/adapters/index.js +14 -0
  336. package/scripts/hooks-system/infrastructure/ast/README.md +198 -0
  337. package/scripts/hooks-system/infrastructure/ast/__tests__/ast-core.spec.js +160 -0
  338. package/scripts/hooks-system/infrastructure/ast/__tests__/ast-intelligence.spec.js +20 -0
  339. package/scripts/hooks-system/infrastructure/ast/android/__tests__/ast-android.spec.js +33 -0
  340. package/scripts/hooks-system/infrastructure/ast/android/__tests__/clean-architecture-analyzer.spec.js +96 -0
  341. package/scripts/hooks-system/infrastructure/ast/android/__tests__/ddd-analyzer.spec.js +113 -0
  342. package/scripts/hooks-system/infrastructure/ast/android/__tests__/detekt-runner.spec.js +36 -0
  343. package/scripts/hooks-system/infrastructure/ast/android/__tests__/feature-first-analyzer.spec.js +80 -0
  344. package/scripts/hooks-system/infrastructure/ast/android/__tests__/native-bridge.spec.js +31 -0
  345. package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidASTIntelligentAnalyzer.js +15 -0
  346. package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidASTParser.js +157 -0
  347. package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidAnalysisOrchestrator.js +164 -0
  348. package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidArchitectureDetector.js +334 -0
  349. package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidClassAnalyzer.js +162 -0
  350. package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidForbiddenLiteralsAnalyzer.js +261 -0
  351. package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidSOLIDAnalyzer.js +287 -0
  352. package/scripts/hooks-system/infrastructure/ast/android/analyzers/__tests__/AndroidForbiddenLiteralsAnalyzer.spec.js +58 -0
  353. package/scripts/hooks-system/infrastructure/ast/android/analyzers/__tests__/AndroidSOLIDAnalyzer.spec.js +84 -0
  354. package/scripts/hooks-system/infrastructure/ast/android/ast-android.js +1785 -0
  355. package/scripts/hooks-system/infrastructure/ast/android/clean-architecture-analyzer.js +115 -0
  356. package/scripts/hooks-system/infrastructure/ast/android/ddd-analyzer.js +70 -0
  357. package/scripts/hooks-system/infrastructure/ast/android/detekt-runner.js +81 -0
  358. package/scripts/hooks-system/infrastructure/ast/android/feature-first-analyzer.js +53 -0
  359. package/scripts/hooks-system/infrastructure/ast/android/native-bridge.js +119 -0
  360. package/scripts/hooks-system/infrastructure/ast/archive/README.md +18 -0
  361. package/scripts/hooks-system/infrastructure/ast/archive/ast-intelligence.ts +276 -0
  362. package/scripts/hooks-system/infrastructure/ast/archive/ios-rules.js +329 -0
  363. package/scripts/hooks-system/infrastructure/ast/archive/kotlin-analyzer.js +332 -0
  364. package/scripts/hooks-system/infrastructure/ast/archive/kotlin-parser.js +303 -0
  365. package/scripts/hooks-system/infrastructure/ast/archive/swift-analyzer.js +390 -0
  366. package/scripts/hooks-system/infrastructure/ast/ast-core.js +594 -0
  367. package/scripts/hooks-system/infrastructure/ast/ast-intelligence.js +617 -0
  368. package/scripts/hooks-system/infrastructure/ast/backend/__tests__/ast-backend.spec.js +20 -0
  369. package/scripts/hooks-system/infrastructure/ast/backend/__tests__/clean-architecture-analyzer.spec.js +151 -0
  370. package/scripts/hooks-system/infrastructure/ast/backend/__tests__/ddd-analyzer.spec.js +124 -0
  371. package/scripts/hooks-system/infrastructure/ast/backend/__tests__/feature-first-analyzer.spec.js +128 -0
  372. package/scripts/hooks-system/infrastructure/ast/backend/__tests__/forbidden-literals-analyzer.spec.js +95 -0
  373. package/scripts/hooks-system/infrastructure/ast/backend/__tests__/nestjs-patterns-analyzer.spec.js +59 -0
  374. package/scripts/hooks-system/infrastructure/ast/backend/__tests__/solid-analyzer.spec.js +114 -0
  375. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/BackendArchitectureDetector.js +141 -0
  376. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/BackendPatternDetector.js +23 -0
  377. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/__tests__/BackendArchitectureDetector.spec.js +239 -0
  378. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/__tests__/BackendPatternDetector.spec.js +58 -0
  379. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/CQRSDetector.js +41 -0
  380. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/CleanArchitectureDetector.js +52 -0
  381. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/FeatureFirstCleanDetector.js +74 -0
  382. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/LayeredArchitectureDetector.js +25 -0
  383. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/MVCDetector.js +32 -0
  384. package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/OnionArchitectureDetector.js +32 -0
  385. package/scripts/hooks-system/infrastructure/ast/backend/ast-backend-clean.js +44 -0
  386. package/scripts/hooks-system/infrastructure/ast/backend/ast-backend.js +2048 -0
  387. package/scripts/hooks-system/infrastructure/ast/backend/clean-architecture-analyzer.js +142 -0
  388. package/scripts/hooks-system/infrastructure/ast/backend/ddd-analyzer.js +256 -0
  389. package/scripts/hooks-system/infrastructure/ast/backend/feature-first-analyzer.js +70 -0
  390. package/scripts/hooks-system/infrastructure/ast/backend/forbidden-literals-analyzer.js +236 -0
  391. package/scripts/hooks-system/infrastructure/ast/backend/nestjs-patterns-analyzer.js +11 -0
  392. package/scripts/hooks-system/infrastructure/ast/backend/solid-analyzer.js +392 -0
  393. package/scripts/hooks-system/infrastructure/ast/common/BDDTDDWorkflowRules.js +52 -0
  394. package/scripts/hooks-system/infrastructure/ast/common/__tests__/BDDTDDWorkflowRules.spec.js +133 -0
  395. package/scripts/hooks-system/infrastructure/ast/common/__tests__/ast-common.spec.js +20 -0
  396. package/scripts/hooks-system/infrastructure/ast/common/__tests__/documentation-analyzer.spec.js +120 -0
  397. package/scripts/hooks-system/infrastructure/ast/common/__tests__/images-backend-analyzer.spec.js +123 -0
  398. package/scripts/hooks-system/infrastructure/ast/common/__tests__/monorepo-health-analyzer.spec.js +118 -0
  399. package/scripts/hooks-system/infrastructure/ast/common/__tests__/network-resilience-analyzer.spec.js +180 -0
  400. package/scripts/hooks-system/infrastructure/ast/common/__tests__/offline-backend-analyzer.spec.js +111 -0
  401. package/scripts/hooks-system/infrastructure/ast/common/__tests__/push-backend-analyzer.spec.js +124 -0
  402. package/scripts/hooks-system/infrastructure/ast/common/ast-common.js +345 -0
  403. package/scripts/hooks-system/infrastructure/ast/common/documentation-analyzer.js +217 -0
  404. package/scripts/hooks-system/infrastructure/ast/common/images-backend-analyzer.js +36 -0
  405. package/scripts/hooks-system/infrastructure/ast/common/monorepo-health-analyzer.js +452 -0
  406. package/scripts/hooks-system/infrastructure/ast/common/network-resilience-analyzer.js +178 -0
  407. package/scripts/hooks-system/infrastructure/ast/common/offline-backend-analyzer.js +53 -0
  408. package/scripts/hooks-system/infrastructure/ast/common/push-backend-analyzer.js +42 -0
  409. package/scripts/hooks-system/infrastructure/ast/common/rules/BDDRules.js +87 -0
  410. package/scripts/hooks-system/infrastructure/ast/common/rules/ImplementationRules.js +83 -0
  411. package/scripts/hooks-system/infrastructure/ast/common/rules/TDDRules.js +109 -0
  412. package/scripts/hooks-system/infrastructure/ast/common/rules/WorkflowRules.js +137 -0
  413. package/scripts/hooks-system/infrastructure/ast/frontend/__tests__/ast-frontend.spec.js +20 -0
  414. package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/FrontendArchitectureDetector.js +289 -0
  415. package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/FrontendForbiddenLiteralsAnalyzer.js +257 -0
  416. package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/FrontendSOLIDAnalyzer.js +274 -0
  417. package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/__tests__/FrontendArchitectureDetector.spec.js +151 -0
  418. package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/__tests__/FrontendForbiddenLiteralsAnalyzer.spec.js +20 -0
  419. package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/__tests__/FrontendSOLIDAnalyzer.spec.js +108 -0
  420. package/scripts/hooks-system/infrastructure/ast/frontend/ast-frontend-clean.js +42 -0
  421. package/scripts/hooks-system/infrastructure/ast/frontend/ast-frontend.js +2094 -0
  422. package/scripts/hooks-system/infrastructure/ast/frontend/clean-architecture-analyzer.js +88 -0
  423. package/scripts/hooks-system/infrastructure/ast/frontend/ddd-analyzer.js +94 -0
  424. package/scripts/hooks-system/infrastructure/ast/frontend/feature-first-analyzer.js +51 -0
  425. package/scripts/hooks-system/infrastructure/ast/ios/__tests__/ast-ios.spec.js +40 -0
  426. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSArchitectureDetector.spec.js +20 -0
  427. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSArchitectureRules.spec.js +61 -0
  428. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSCICDRules.spec.js +10 -0
  429. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSEnterpriseAnalyzer.spec.js +36 -0
  430. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSForbiddenLiteralsAnalyzer.spec.js +64 -0
  431. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSNetworkingAdvancedRules.spec.js +10 -0
  432. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSPerformanceRules.spec.js +34 -0
  433. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSSPMRules.spec.js +10 -0
  434. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSSwiftUIAdvancedRules.spec.js +10 -0
  435. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSASTIntelligentAnalyzer.js +894 -0
  436. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSArchitectureDetector.js +445 -0
  437. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSArchitectureRules.js +700 -0
  438. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSCICDRules.js +431 -0
  439. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSEnterpriseAnalyzer.js +580 -0
  440. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSForbiddenLiteralsAnalyzer.js +261 -0
  441. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSNetworkingAdvancedRules.js +177 -0
  442. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSPerformanceRules.js +11 -0
  443. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSSPMRules.js +496 -0
  444. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSSwiftUIAdvancedRules.js +333 -0
  445. package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSTestingAdvancedRules.js +225 -0
  446. package/scripts/hooks-system/infrastructure/ast/ios/ast-ios.js +2176 -0
  447. package/scripts/hooks-system/infrastructure/ast/ios/native-bridge.js +92 -0
  448. package/scripts/hooks-system/infrastructure/ast/ios/parsers/SourceKittenParser.js +471 -0
  449. package/scripts/hooks-system/infrastructure/ast/ios/parsers/__tests__/SourceKittenParser.spec.js +41 -0
  450. package/scripts/hooks-system/infrastructure/ast/text/__tests__/text-scanner.spec.js +20 -0
  451. package/scripts/hooks-system/infrastructure/ast/text/text-scanner.js +1120 -0
  452. package/scripts/hooks-system/infrastructure/cache/CacheService.js +160 -0
  453. package/scripts/hooks-system/infrastructure/cli/__tests__/install-wizard.spec.js +16 -0
  454. package/scripts/hooks-system/infrastructure/cli/install-wizard.js +74 -0
  455. package/scripts/hooks-system/infrastructure/core/GitOperations.js +50 -0
  456. package/scripts/hooks-system/infrastructure/core/GitOperations.ts +112 -0
  457. package/scripts/hooks-system/infrastructure/core/__tests__/GitOperations.spec.js +146 -0
  458. package/scripts/hooks-system/infrastructure/eslint/eslint-integration.sh +75 -0
  459. package/scripts/hooks-system/infrastructure/events/EventListeners.js +143 -0
  460. package/scripts/hooks-system/infrastructure/events/__tests__/events.spec.js +14 -0
  461. package/scripts/hooks-system/infrastructure/external-tools/GitOperations.js +54 -0
  462. package/scripts/hooks-system/infrastructure/external-tools/eslint/backend.config.template.mjs +58 -0
  463. package/scripts/hooks-system/infrastructure/git-hooks/pre-push +35 -0
  464. package/scripts/hooks-system/infrastructure/git-server/pre-receive-hook +253 -0
  465. package/scripts/hooks-system/infrastructure/guards/git-wrapper.sh +32 -0
  466. package/scripts/hooks-system/infrastructure/guards/master-validator.sh +247 -0
  467. package/scripts/hooks-system/infrastructure/guards/prevent-no-verify.sh +34 -0
  468. package/scripts/hooks-system/infrastructure/hooks/__tests__/skill-activation-prompt.spec.js +11 -0
  469. package/scripts/hooks-system/infrastructure/hooks/pre-tool-use-intelligent-enforcer.sh +489 -0
  470. package/scripts/hooks-system/infrastructure/hooks/skill-activation-prompt.js +244 -0
  471. package/scripts/hooks-system/infrastructure/logging/UnifiedLoggerFactory.js +40 -0
  472. package/scripts/hooks-system/infrastructure/logging/__tests__/logging.spec.js +9 -0
  473. package/scripts/hooks-system/infrastructure/mcp/README.md +116 -0
  474. package/scripts/hooks-system/infrastructure/mcp/__tests__/ast-intelligence-automation.spec.js +38 -0
  475. package/scripts/hooks-system/infrastructure/mcp/__tests__/evidence-watcher.spec.js +38 -0
  476. package/scripts/hooks-system/infrastructure/mcp/ast-intelligence-automation.js +1097 -0
  477. package/scripts/hooks-system/infrastructure/mcp/evidence-watcher.js +128 -0
  478. package/scripts/hooks-system/infrastructure/mcp/package.json +17 -0
  479. package/scripts/hooks-system/infrastructure/mcp/services/EvidenceService.js +87 -0
  480. package/scripts/hooks-system/infrastructure/mcp/services/McpProtocolHandler.js +166 -0
  481. package/scripts/hooks-system/infrastructure/orchestration/__tests__/intelligent-audit.spec.js +11 -0
  482. package/scripts/hooks-system/infrastructure/orchestration/intelligent-audit.js +353 -0
  483. package/scripts/hooks-system/infrastructure/patterns/pattern-checks.sh +98 -0
  484. package/scripts/hooks-system/infrastructure/reporting/ReportImpactAnalyzer.js +109 -0
  485. package/scripts/hooks-system/infrastructure/reporting/ReportMetricsCalculator.js +114 -0
  486. package/scripts/hooks-system/infrastructure/reporting/ReportPresenter.js +86 -0
  487. package/scripts/hooks-system/infrastructure/reporting/__tests__/reporting.spec.js +15 -0
  488. package/scripts/hooks-system/infrastructure/reporting/report-generator.js +130 -0
  489. package/scripts/hooks-system/infrastructure/reporting/severity-tracker.js +105 -0
  490. package/scripts/hooks-system/infrastructure/repositories/CursorTokenRepository.js +76 -0
  491. package/scripts/hooks-system/infrastructure/repositories/FileFindingsRepository.js +88 -0
  492. package/scripts/hooks-system/infrastructure/repositories/__tests__/repositories.spec.js +20 -0
  493. package/scripts/hooks-system/infrastructure/repositories/datasources/CursorApiDataSource.js +73 -0
  494. package/scripts/hooks-system/infrastructure/repositories/datasources/CursorFileDataSource.js +55 -0
  495. package/scripts/hooks-system/infrastructure/severity/__tests__/severity-evaluator.spec.js +18 -0
  496. package/scripts/hooks-system/infrastructure/severity/analyzers/__tests__/maintainability-analyzer.spec.js +170 -0
  497. package/scripts/hooks-system/infrastructure/severity/analyzers/__tests__/performance-analyzer.spec.js +186 -0
  498. package/scripts/hooks-system/infrastructure/severity/analyzers/__tests__/security-analyzer.spec.js +151 -0
  499. package/scripts/hooks-system/infrastructure/severity/analyzers/__tests__/stability-analyzer.spec.js +143 -0
  500. package/scripts/hooks-system/infrastructure/severity/analyzers/maintainability-analyzer.js +100 -0
  501. package/scripts/hooks-system/infrastructure/severity/analyzers/performance-analyzer.js +109 -0
  502. package/scripts/hooks-system/infrastructure/severity/analyzers/security-analyzer.js +104 -0
  503. package/scripts/hooks-system/infrastructure/severity/analyzers/stability-analyzer.js +85 -0
  504. package/scripts/hooks-system/infrastructure/severity/context/analyzers/CodeClassificationAnalyzer.js +71 -0
  505. package/scripts/hooks-system/infrastructure/severity/context/analyzers/DataAnalyzer.js +64 -0
  506. package/scripts/hooks-system/infrastructure/severity/context/analyzers/ImpactAnalyzer.js +68 -0
  507. package/scripts/hooks-system/infrastructure/severity/context/analyzers/SafetyAnalyzer.js +82 -0
  508. package/scripts/hooks-system/infrastructure/severity/context/context-builder.js +88 -0
  509. package/scripts/hooks-system/infrastructure/severity/generators/RecommendationGenerator.js +153 -0
  510. package/scripts/hooks-system/infrastructure/severity/mappers/SeverityMapper.js +10 -0
  511. package/scripts/hooks-system/infrastructure/severity/policies/gate-policies.js +136 -0
  512. package/scripts/hooks-system/infrastructure/severity/policies/severity-policies.json +206 -0
  513. package/scripts/hooks-system/infrastructure/severity/scorers/ContextMultiplier.js +49 -0
  514. package/scripts/hooks-system/infrastructure/severity/severity-evaluator.js +117 -0
  515. package/scripts/hooks-system/infrastructure/shell/core/constants.sh +26 -0
  516. package/scripts/hooks-system/infrastructure/shell/core/utils.sh +45 -0
  517. package/scripts/hooks-system/infrastructure/shell/gitflow/git-wrapper.sh +646 -0
  518. package/scripts/hooks-system/infrastructure/shell/gitflow/gitflow-enforcer.sh +620 -0
  519. package/scripts/hooks-system/infrastructure/shell/gitflow/gitflow-state-manager.sh +235 -0
  520. package/scripts/hooks-system/infrastructure/shell/gitflow-state-manager.sh +225 -0
  521. package/scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh +1106 -0
  522. package/scripts/hooks-system/infrastructure/shell/security/detect-secrets.sh +26 -0
  523. package/scripts/hooks-system/infrastructure/shell/security/detect_secrets.py +182 -0
  524. package/scripts/hooks-system/infrastructure/shell/validate-clean-architecture.sh +254 -0
  525. package/scripts/hooks-system/infrastructure/shell/validators/check-doc-structure.sh +62 -0
  526. package/scripts/hooks-system/infrastructure/shell/validators/ensure-critical-docs.sh +26 -0
  527. package/scripts/hooks-system/infrastructure/shell/validators/validate-ai-protocol.sh +474 -0
  528. package/scripts/hooks-system/infrastructure/shell/validators/validate-clean-architecture.sh +303 -0
  529. package/scripts/hooks-system/infrastructure/shell/validators/validate-conventional-commit.sh +42 -0
  530. package/scripts/hooks-system/infrastructure/storage/file-operations.sh +31 -0
  531. package/scripts/hooks-system/infrastructure/telemetry/TelemetryService.js +165 -0
  532. package/scripts/hooks-system/infrastructure/telemetry/__tests__/telemetry.spec.js +15 -0
  533. package/scripts/hooks-system/infrastructure/telemetry/metrics-logger.js +66 -0
  534. package/scripts/hooks-system/infrastructure/telemetry/metrics-server.js +61 -0
  535. package/scripts/hooks-system/infrastructure/utils/__tests__/utils.spec.js +8 -0
  536. package/scripts/hooks-system/infrastructure/utils/error-utils.js +28 -0
  537. package/scripts/hooks-system/infrastructure/utils/timestamp-helper.sh +106 -0
  538. package/scripts/hooks-system/infrastructure/utils/token-manager.js +121 -0
  539. package/scripts/hooks-system/infrastructure/validators/__tests__/detect-commit-language.spec.js +16 -0
  540. package/scripts/hooks-system/infrastructure/validators/__tests__/enforce-english-literals.spec.js +67 -0
  541. package/scripts/hooks-system/infrastructure/validators/detect-commit-language.js +145 -0
  542. package/scripts/hooks-system/infrastructure/validators/enforce-english-literals.js +202 -0
  543. package/scripts/hooks-system/infrastructure/watchdog/__tests__/.audit-reports/token-monitor.log +18 -0
  544. package/scripts/hooks-system/infrastructure/watchdog/__tests__/auto-recovery.spec.js +14 -0
  545. package/scripts/hooks-system/infrastructure/watchdog/__tests__/token-monitor.spec.js +67 -0
  546. package/scripts/hooks-system/infrastructure/watchdog/__tests__/watchdog.spec.js +22 -0
  547. package/scripts/hooks-system/infrastructure/watchdog/ai-watchdog.sh +278 -0
  548. package/scripts/hooks-system/infrastructure/watchdog/auto-recovery.js +32 -0
  549. package/scripts/hooks-system/infrastructure/watchdog/health-check.js +58 -0
  550. package/scripts/hooks-system/infrastructure/watchdog/token-monitor-loop.sh +20 -0
  551. package/scripts/hooks-system/infrastructure/watchdog/token-monitor.js +69 -0
  552. package/scripts/hooks-system/infrastructure/watchdog/token-tracker.sh +208 -0
  553. package/scripts/hooks-system/presentation/cli/audit.sh +32 -0
  554. package/scripts/hooks-system/presentation/cli/autonomous-status.sh +92 -0
  555. package/scripts/hooks-system/presentation/cli/categorize-violations.sh +179 -0
  556. package/scripts/hooks-system/presentation/cli/direct-audit-option2.sh +23 -0
  557. package/scripts/hooks-system/presentation/cli/direct-audit.sh +33 -0
  558. package/skills/android-guidelines/SKILL.md +475 -0
  559. package/skills/android-guidelines/resources/advanced-topics.md +44 -0
  560. package/skills/android-guidelines/resources/architecture-overview.md +44 -0
  561. package/skills/backend-guidelines/SKILL.md +335 -0
  562. package/skills/backend-guidelines/resources/architecture-overview.md +48 -0
  563. package/skills/frontend-guidelines/SKILL.md +367 -0
  564. package/skills/frontend-guidelines/resources/architecture-overview.md +44 -0
  565. package/skills/ios-guidelines/SKILL.md +406 -0
  566. package/skills/ios-guidelines/resources/architecture-overview.md +47 -0
  567. package/skills/skill-rules.json +334 -0
@@ -0,0 +1,1106 @@
1
+ #!/usr/bin/env bash
2
+ # Audit Orchestrator - Infrastructure Layer
3
+ # Coordinates the execution of audit checks following Clean Architecture principles
4
+
5
+ set -euo pipefail
6
+
7
+ # Get hooks-system directory
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+
10
+ # Detect if running from node_modules or scripts/hooks-system
11
+ if [[ "$SCRIPT_DIR" == *"node_modules/@pumuki/ast-intelligence-hooks"* ]]; then
12
+ # Running from installed npm package
13
+ # SCRIPT_DIR is: node_modules/@pumuki/ast-intelligence-hooks/infrastructure/shell/orchestrators
14
+ # Need to go up 3 levels: ../../.. = node_modules/@pumuki/ast-intelligence-hooks
15
+ HOOKS_SYSTEM_DIR="$(cd "$SCRIPT_DIR/../../.." && pwd)"
16
+ elif [[ "$SCRIPT_DIR" == *"scripts/hooks-system"* ]]; then
17
+ # Running from local scripts/hooks-system
18
+ # SCRIPT_DIR is: scripts/hooks-system/infrastructure/shell/orchestrators
19
+ # Find the hooks-system directory by searching up the path
20
+ CURRENT_DIR="$SCRIPT_DIR"
21
+ while [[ "$CURRENT_DIR" != "/" ]] && [[ "$CURRENT_DIR" != "." ]]; do
22
+ if [[ "$(basename "$CURRENT_DIR")" == "hooks-system" ]]; then
23
+ HOOKS_SYSTEM_DIR="$CURRENT_DIR"
24
+ break
25
+ fi
26
+ CURRENT_DIR="$(dirname "$CURRENT_DIR")"
27
+ done
28
+ if [[ -z "${HOOKS_SYSTEM_DIR:-}" ]] || [[ ! -d "$HOOKS_SYSTEM_DIR" ]]; then
29
+ echo "Error: Could not find hooks-system directory from $SCRIPT_DIR" >&2
30
+ exit 1
31
+ fi
32
+ else
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"
39
+ else
40
+ echo "Error: Could not determine HOOKS_SYSTEM_DIR" >&2
41
+ echo " SCRIPT_DIR: $SCRIPT_DIR" >&2
42
+ echo " REPO_ROOT: $REPO_ROOT" >&2
43
+ exit 1
44
+ fi
45
+ fi
46
+
47
+ INFRASTRUCTURE_DIR="$HOOKS_SYSTEM_DIR/infrastructure"
48
+ AST_DIR="$INFRASTRUCTURE_DIR/ast"
49
+
50
+ # Source infrastructure modules
51
+ source "$INFRASTRUCTURE_DIR/shell/core/constants.sh"
52
+ source "$INFRASTRUCTURE_DIR/shell/core/utils.sh"
53
+ source "$INFRASTRUCTURE_DIR/storage/file-operations.sh"
54
+ source "$INFRASTRUCTURE_DIR/patterns/pattern-checks.sh"
55
+ source "$INFRASTRUCTURE_DIR/eslint/eslint-integration.sh"
56
+
57
+ # Initialize
58
+ START_TIME=$(date +%s)
59
+ ROOT_DIR=$(pwd)
60
+
61
+ # Default to temp directories to avoid polluting repositories.
62
+ # Can be overridden by setting AUDIT_TMP / AUDIT_REPORTS.
63
+ PROJECT_NAME="$(basename "$ROOT_DIR")"
64
+ TMP_BASE_DIR="${TMPDIR:-/tmp}/pumuki-audit/${PROJECT_NAME}"
65
+ TMP_DIR="${AUDIT_TMP:-${TMP_BASE_DIR}/.audit_tmp}"
66
+ REPORTS_DIR="${AUDIT_REPORTS:-${TMP_BASE_DIR}/.audit-reports}"
67
+ mkdir -p "$TMP_DIR" "$REPORTS_DIR"
68
+
69
+ if [[ -z "${AUDIT_LIBRARY:-}" ]] && [[ -f "$ROOT_DIR/infrastructure/ast/ast-intelligence.js" ]]; then
70
+ export AUDIT_LIBRARY=true
71
+ fi
72
+
73
+ print_signature() {
74
+ printf "${BLUE}"
75
+ cat <<'SIG'
76
+ ██████╗ ██╗ ██╗███╗ ███╗██╗ ██╗██╗ ██╗██╗
77
+ ██╔══██╗██║ ██║████╗ ████║██║ ██║██║ ██╔╝██║
78
+ ██████╔╝██║ ██║██╔████╔██║██║ ██║█████╔╝ ██║
79
+ ██╔═══╝ ██║ ██║██║╚██╔╝██║██║ ██║██╔═██╗ ██║
80
+ ██║ ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║ ██╗██║
81
+ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝
82
+ 🐈 En memoria de Pumuki 💚
83
+ SIG
84
+ printf "${NC}\n"
85
+ }
86
+
87
+ print_final_signature() {
88
+ printf "${BLUE}"
89
+ cat <<'FSIG'
90
+ ██████╗ ██╗ ██╗███╗ ███╗██╗ ██╗██╗ ██╗██╗
91
+ ██╔══██╗██║ ██║████╗ ████║██║ ██║██║ ██╔╝██║
92
+ ██████╔╝██║ ██║██╔████╔██║██║ ██║█████╔╝ ██║
93
+ ██╔═══╝ ██║ ██║██║╚██╔╝██║██║ ██║██╔═██╗ ██║
94
+ ██║ ╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║ ██╗██║
95
+ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝
96
+ 🐈 En memoria de Pumuki 💚
97
+ FSIG
98
+ printf "${NC}\n"
99
+ printf "%b🐈 Senior Software Architect - AI-Driven Development%b\n" "$BLUE" "$NC"
100
+ printf "%bGenerated on: %s%b\n" "$BLUE" "$(date '+%Y-%m-%d %H:%M:%S')" "$NC"
101
+ local project_name=$(basename "$ROOT_DIR")
102
+ printf "%bProject: %s%b\n" "$BLUE" "$project_name" "$NC"
103
+ }
104
+
105
+ print_header() {
106
+ printf "\n"
107
+ print_signature
108
+ printf "%b%s%b\n\n" "$BLUE" "$MSG_TITLE" "$NC"
109
+ }
110
+
111
+ ignored_globs() {
112
+ cat <<'EOF'
113
+ node_modules
114
+ dist
115
+ .next
116
+ .turbo
117
+ .vercel
118
+ coverage
119
+ build
120
+ out
121
+ .cache
122
+ *.min.*
123
+ *.map
124
+ *.d.ts
125
+ *.lock
126
+ *.snap
127
+ *.png
128
+ *.jpg
129
+ *.jpeg
130
+ *.gif
131
+ *.svg
132
+ *.webp
133
+ *.ico
134
+ *.woff*
135
+ *.ttf
136
+ *.eot
137
+ *.pdf
138
+ EOF
139
+ }
140
+
141
+ # Functions moved to their respective modules:
142
+ # - list_source_files, count_files -> infrastructure/storage/file-operations.sh
143
+ # - check_grep -> infrastructure/patterns/pattern-checks.sh
144
+ # - run_eslint_for_app, aggregate_eslint -> infrastructure/eslint/eslint-integration.sh
145
+ # - progress_bar, progress_bar_simple -> infrastructure/shell/utils.sh
146
+
147
+ run_basic_checks() {
148
+ printf "%b%s%b\n" "$YELLOW" "$MSG_COLLECT" "$NC"
149
+ local files_list="$TMP_DIR/files.txt"
150
+ list_source_files "$ROOT_DIR" > "$files_list"
151
+ local total_files
152
+ total_files=$(count_files "$files_list")
153
+ printf " Files scanned: %s\n" "$total_files"
154
+
155
+ printf "\n%b%s%b\n" "$YELLOW" "$MSG_PATTERNS" "$NC"
156
+ run_pattern_checks "$files_list" > "$TMP_DIR/pattern-summary.raw" 2>> "$TMP_DIR/pattern-summary.raw"
157
+ local pattern_keys="TO""DO""_FI""XME|CON""SOLE""_LOG|ANY_TYPE|SQL_RAW|HARDCODED_SECRET|DISABLED_LINT"
158
+ grep -E "^(${pattern_keys}):[0-9]+\$" "$TMP_DIR/pattern-summary.raw" > "$TMP_DIR/pattern-summary.txt" || true
159
+ }
160
+
161
+ run_eslint_suite() {
162
+ run_eslint_suite_impl "$ROOT_DIR" "$TMP_DIR"
163
+ }
164
+
165
+ run_intelligent_audit() {
166
+ local node_bin=""
167
+ node_bin="$(command -v node 2>/dev/null || true)"
168
+ if [[ -z "$node_bin" ]]; then
169
+ if [[ -x "/opt/homebrew/bin/node" ]]; then node_bin="/opt/homebrew/bin/node"; fi
170
+ fi
171
+ if [[ -z "$node_bin" ]]; then
172
+ if [[ -x "/usr/local/bin/node" ]]; then node_bin="/usr/local/bin/node"; fi
173
+ fi
174
+ if [[ -z "$node_bin" ]]; then
175
+ if [[ -x "/usr/bin/node" ]]; then node_bin="/usr/bin/node"; fi
176
+ fi
177
+ if [[ -z "$node_bin" ]]; then
178
+ return 0
179
+ fi
180
+
181
+ local intelligent_audit="$HOOKS_SYSTEM_DIR/infrastructure/orchestration/intelligent-audit.js"
182
+ if [[ ! -f "$intelligent_audit" ]]; then
183
+ return 0
184
+ fi
185
+
186
+ export AUDIT_TMP="$TMP_DIR"
187
+ if [[ "${BLOCK_ON_REPO_VIOLATIONS:-0}" == "1" ]]; then
188
+ export AI_GATE_SCOPE="repo"
189
+ else
190
+ export AI_GATE_SCOPE="staging"
191
+ fi
192
+
193
+ local node_path_value="${NODE_PATH:-}"
194
+ if [[ -d "$HOOKS_SYSTEM_DIR/node_modules" ]]; then
195
+ node_path_value="$HOOKS_SYSTEM_DIR/node_modules${node_path_value:+:$node_path_value}"
196
+ fi
197
+ if [[ -d "$ROOT_DIR/node_modules" ]]; then
198
+ node_path_value="$ROOT_DIR/node_modules${node_path_value:+:$node_path_value}"
199
+ fi
200
+
201
+ if [[ -n "$node_path_value" ]]; then
202
+ (cd "$ROOT_DIR" && export NODE_PATH="$node_path_value" && "$node_bin" "$intelligent_audit" >/dev/null 2>&1) || true
203
+ else
204
+ (cd "$ROOT_DIR" && "$node_bin" "$intelligent_audit" >/dev/null 2>&1) || true
205
+ fi
206
+ }
207
+
208
+ full_audit() {
209
+ run_basic_checks
210
+ run_eslint_suite
211
+ run_ast_intelligence
212
+ run_intelligent_audit
213
+ compute_staged_summary
214
+ summarize_all
215
+ }
216
+
217
+ full_audit_strict_repo_and_staging() {
218
+ export AUDIT_STRICT=1
219
+ export BLOCK_ALL_SEVERITIES=1
220
+ export BLOCK_ON_REPO_VIOLATIONS=1
221
+ full_audit
222
+ }
223
+
224
+ full_audit_strict_staging_only() {
225
+ export AUDIT_STRICT=1
226
+ export BLOCK_ALL_SEVERITIES=1
227
+ export STAGING_ONLY_MODE=1
228
+
229
+ printf "%b%s%b\n" "$YELLOW" "🎯 STRICT STAGING-ONLY MODE" "$NC"
230
+ printf "Analyzing only staged files with strict quality gates...\n\n"
231
+
232
+ if ! command -v git >/dev/null 2>&1; then
233
+ printf "%b[ERROR] Git not available%b\n" "$RED" "$NC"
234
+ exit 1
235
+ fi
236
+
237
+ local staged_count=$(git diff --cached --name-only --diff-filter=ACM | wc -l | tr -d ' ')
238
+ if [[ "$staged_count" == "0" ]]; then
239
+ printf "%b[INFO] No staged files%b\n" "$YELLOW" "$NC"
240
+ exit 0
241
+ fi
242
+
243
+ printf "Staged files: %s\n\n" "$staged_count"
244
+
245
+ run_ast_intelligence
246
+ compute_staged_summary
247
+
248
+ local gate_crit=${STAGED_CRIT:-0}
249
+ local gate_high=${STAGED_HIGH:-0}
250
+ local gate_med=${STAGED_MED:-0}
251
+ local gate_low=${STAGED_LOW:-0}
252
+
253
+ printf "\n%b═══════════════════════════════════════════════════════════════%b\n" "$BLUE" "$NC"
254
+ printf "%bSTAGING AREA VERDICT%b\n" "$BLUE" "$NC"
255
+ printf "%b═══════════════════════════════════════════════════════════════%b\n" "$BLUE" "$NC"
256
+
257
+ if (( gate_crit > 0 || gate_high > 0 || gate_med > 0 || gate_low > 0 )); then
258
+ printf "\n%b❌ COMMIT BLOCKED - STRICT MODE%b\n" "$RED" "$NC"
259
+ printf " 🔴 CRITICAL: %s\n" "$gate_crit"
260
+ printf " 🟠 HIGH: %s\n" "$gate_high"
261
+ printf " 🟡 MEDIUM: %s\n" "$gate_med"
262
+ printf " 🔵 LOW: %s\n" "$gate_low"
263
+ printf "\n Action: Fix ALL violations in staged files.\n"
264
+ printf "\n"
265
+ print_final_signature
266
+ exit 1
267
+ else
268
+ printf "\n%b✅ STAGING CLEAN - COMMIT ALLOWED%b\n" "$GREEN" "$NC"
269
+ printf " 🔴 CRITICAL: 0\n"
270
+ printf " 🟠 HIGH: 0\n"
271
+ printf " 🟡 MEDIUM: 0\n"
272
+ printf " 🔵 LOW: 0\n"
273
+ printf "\n All staged files pass strict quality gates.\n"
274
+ printf " Ready to commit! 🚀\n\n"
275
+ print_final_signature
276
+ exit 0
277
+ fi
278
+ }
279
+
280
+ full_audit_standard() {
281
+ export AUDIT_STRICT=1
282
+ export BLOCK_ALL_SEVERITIES=0
283
+ export STAGING_ONLY_MODE=1
284
+
285
+ printf "%b%s%b\n" "$YELLOW" "🎯 STANDARD MODE (CRITICAL/HIGH in staging)" "$NC"
286
+ printf "Analyzing only staged files - blocks on CRITICAL/HIGH only...\n\n"
287
+
288
+ if ! command -v git >/dev/null 2>&1; then
289
+ printf "%b[ERROR] Git not available%b\n" "$RED" "$NC"
290
+ exit 1
291
+ fi
292
+
293
+ local staged_count=$(git diff --cached --name-only --diff-filter=ACM | wc -l | tr -d ' ')
294
+ if [[ "$staged_count" == "0" ]]; then
295
+ printf "%b[INFO] No staged files%b\n" "$YELLOW" "$NC"
296
+ exit 0
297
+ fi
298
+
299
+ printf "Staged files: %s\n\n" "$staged_count"
300
+
301
+ run_ast_intelligence
302
+ compute_staged_summary
303
+
304
+ local gate_crit=${STAGED_CRIT:-0}
305
+ local gate_high=${STAGED_HIGH:-0}
306
+ local gate_med=${STAGED_MED:-0}
307
+ local gate_low=${STAGED_LOW:-0}
308
+
309
+ printf "\n%b═══════════════════════════════════════════════════════════════%b\n" "$BLUE" "$NC"
310
+ printf "%bSTAGING AREA VERDICT%b\n" "$BLUE" "$NC"
311
+ printf "%b═══════════════════════════════════════════════════════════════%b\n" "$BLUE" "$NC"
312
+
313
+ if (( gate_crit > 0 || gate_high > 0 )); then
314
+ printf "\n%b❌ COMMIT BLOCKED - CRITICAL/HIGH%b\n" "$RED" "$NC"
315
+ printf " 🔴 CRITICAL: %s\n" "$gate_crit"
316
+ printf " 🟠 HIGH: %s\n" "$gate_high"
317
+ printf " 🟡 MEDIUM: %s (allowed)\n" "$gate_med"
318
+ printf " 🔵 LOW: %s (allowed)\n" "$gate_low"
319
+ printf "\n Action: Fix CRITICAL/HIGH violations in staged files.\n"
320
+ printf "\n"
321
+ print_final_signature
322
+ exit 1
323
+ else
324
+ printf "\n%b✅ STAGING CLEAN - COMMIT ALLOWED%b\n" "$GREEN" "$NC"
325
+ printf " 🔴 CRITICAL: 0\n"
326
+ printf " 🟠 HIGH: 0\n"
327
+ printf " 🟡 MEDIUM: %s (allowed)\n" "$gate_med"
328
+ printf " 🔵 LOW: %s (allowed)\n" "$gate_low"
329
+ printf "\n Staged files pass critical/high quality gates.\n"
330
+ printf " Ready to commit! 🚀\n\n"
331
+ print_final_signature
332
+ exit 0
333
+ fi
334
+ }
335
+ compute_staged_summary() {
336
+ if ! command -v git >/dev/null 2>&1; then return; fi
337
+ local staged_file="$TMP_DIR/staged.txt"
338
+ git diff --cached --name-only --diff-filter=ACM | sed "s|^|$ROOT_DIR/|" > "$staged_file" || true
339
+ if [[ ! -s "$staged_file" ]]; then return; fi
340
+ printf "\n%bStaging Area%b\n" "$YELLOW" "$NC"
341
+ printf "─────────────────────────────────────────────────────────────\n"
342
+
343
+ run_pattern_checks "$staged_file" > "$TMP_DIR/pattern-staged.raw"
344
+ local pattern_keys_staged="TO""DO""_FI""XME|CON""SOLE""_LOG|ANY_TYPE|SQL_RAW|HARDCODED_SECRET|DISABLED_LINT"
345
+ grep -E "^(${pattern_keys_staged}):[0-9]+\$" "$TMP_DIR/pattern-staged.raw" > "$TMP_DIR/pattern-staged.txt" || true
346
+ while IFS=: read -r k v; do
347
+ [[ -z "$k" ]] && continue
348
+ printf " %s %s: %s\n" "$([[ $k =~ ANY_TYPE|SQL_RAW|HARDCODED_SECRET ]] && echo "$EMJ_ERR" || echo "$EMJ_WARN")" "$k" "${v:-0}"
349
+ done < "$TMP_DIR/pattern-staged.txt"
350
+
351
+ if [[ -f "$TMP_DIR/ast-summary.json" ]] && command -v jq >/dev/null 2>&1; then
352
+ local scrit=0 shigh=0 smed=0 slow=0
353
+ while IFS= read -r fpath; do
354
+ [[ -z "$fpath" ]] && continue
355
+ local ccrit chigh cmed clow
356
+ ccrit=$(jq -r --arg p "$fpath" '[ .findings[] | select(.filePath == $p) | .severity | ascii_downcase | if .=="critical" or .=="error" then 1 else 0 end ] | add // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
357
+ chigh=$(jq -r --arg p "$fpath" '[ .findings[] | select(.filePath == $p) | .severity | ascii_downcase | if .=="high" then 1 else 0 end ] | add // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
358
+ cmed=$(jq -r --arg p "$fpath" '[ .findings[] | select(.filePath == $p) | .severity | ascii_downcase | if .=="warning" or .=="medium" then 1 else 0 end ] | add // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
359
+ clow=$(jq -r --arg p "$fpath" '[ .findings[] | select(.filePath == $p) | .severity | ascii_downcase | if .=="info" or .=="low" then 1 else 0 end ] | add // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
360
+ scrit=$((scrit + ccrit)); shigh=$((shigh + chigh)); smed=$((smed + cmed)); slow=$((slow + clow))
361
+ done < "$staged_file"
362
+ printf " Staged AST → 🔴 CRITICAL:%s 🟠 HIGH:%s 🟡 MEDIUM:%s 🔵 LOW:%s\n" "${scrit:-0}" "${shigh:-0}" "${smed:-0}" "${slow:-0}"
363
+ export STAGED_CRIT=${scrit:-0}
364
+ export STAGED_HIGH=${shigh:-0}
365
+ export STAGED_MED=${smed:-0}
366
+ export STAGED_LOW=${slow:-0}
367
+ fi
368
+ }
369
+
370
+ get_recommendation() {
371
+ local rule_id="$1"
372
+ local count="$2"
373
+ case "$rule_id" in
374
+ "types.any")
375
+ printf " → Replace 'any' with specific types. Use TypeScript strict mode.\n"
376
+ printf " → Impact: Type safety compromised, potential runtime errors.\n"
377
+ ;;
378
+ "security.secret")
379
+ printf " → Move secrets to environment variables (.env).\n"
380
+ printf " → Impact: %bCRITICAL%b - Credentials exposed in source code.\n" "$RED" "$NC"
381
+ ;;
382
+ "security.sql.raw")
383
+ printf " → Use parameterized queries or ORM methods.\n"
384
+ printf " → Impact: %bCRITICAL%b - SQL injection vulnerability.\n" "$RED" "$NC"
385
+ ;;
386
+ "architecture.layering")
387
+ printf " → Fix dependency direction: domain should not depend on infrastructure.\n"
388
+ printf " → Impact: %bCRITICAL%b - Clean Architecture violation.\n" "$RED" "$NC"
389
+ ;;
390
+ "performance.pagination")
391
+ printf " → Add .range() or .limit() to Supabase queries.\n"
392
+ printf " → Impact: %bMEDIUM%b - Potential memory issues with large datasets.\n" "$YELLOW" "$NC"
393
+ ;;
394
+ "performance.nplus1")
395
+ printf " → Batch queries or use eager loading patterns.\n"
396
+ printf " → Impact: %bMEDIUM%b - Excessive database calls.\n" "$YELLOW" "$NC"
397
+ ;;
398
+ "debug.console")
399
+ printf " → Replace with proper logging service (Winston, Pino).\n"
400
+ printf " → Impact: %bLOW%b - Debug code in production.\n" "$BLUE" "$NC"
401
+ ;;
402
+ *)
403
+ printf " → Review and fix violations.\n"
404
+ ;;
405
+ esac
406
+ }
407
+
408
+ print_platform_summary() {
409
+ local platform="$1"
410
+ local json_file="$2"
411
+ if ! command -v jq >/dev/null 2>&1; then
412
+ return
413
+ fi
414
+ local crit high med low files
415
+ crit=$(jq -r --arg p "$platform" '.platformDetails[$p].CRITICAL // 0' "$json_file" 2>/dev/null || echo "0")
416
+ high=$(jq -r --arg p "$platform" '.platformDetails[$p].HIGH // 0' "$json_file" 2>/dev/null || echo "0")
417
+ med=$(jq -r --arg p "$platform" '.platformDetails[$p].MEDIUM // 0' "$json_file" 2>/dev/null || echo "0")
418
+ low=$(jq -r --arg p "$platform" '.platformDetails[$p].LOW // 0' "$json_file" 2>/dev/null || echo "0")
419
+ files=$(jq -r --arg p "$platform" '.platformDetails[$p].files | length // 0' "$json_file" 2>/dev/null || echo "0")
420
+ if [[ "$crit" == "0" && "$high" == "0" && "$med" == "0" && "$low" == "0" ]]; then
421
+ return
422
+ fi
423
+ printf "\n Platform: %s\n" "$platform"
424
+ printf " ──────────────────────────────────────────────\n"
425
+ printf " 🔴 CRITICAL: %s 🟠 HIGH: %s 🟡 MEDIUM: %s 🔵 LOW: %s\n" "$crit" "$high" "$med" "$low"
426
+ printf " Files affected: %s\n" "$files"
427
+ local top_rules
428
+ top_rules=$(jq -r --arg p "$platform" '.platformDetails[$p].rules | to_entries | sort_by(-.value) | .[0:5] | .[] | (.key + ": " + (.value | tostring))' "$json_file" 2>/dev/null | sed 's/^/ /' || echo "")
429
+ if [[ -n "$top_rules" ]]; then
430
+ printf " Top violations:\n%s\n" "$top_rules"
431
+ fi
432
+ }
433
+
434
+ summarize_all() {
435
+ printf "\n"
436
+ printf "%b═══════════════════════════════════════════════════════════════%b\n" "$BLUE" "$NC"
437
+ printf "%b%s%b\n" "$BLUE" "$MSG_SUMMARY" "$NC"
438
+ printf "%b═══════════════════════════════════════════════════════════════%b\n\n" "$BLUE" "$NC"
439
+
440
+ # Quick summary at the top
441
+ local es_err es_warn crit high med low total_violations files_scanned
442
+ es_err=$(grep -o 'errors=[0-9]\+' "$TMP_DIR/eslint-summary.txt" 2>/dev/null | head -n1 | sed 's/[^0-9]//g')
443
+ es_warn=$(grep -o 'warnings=[0-9]\+' "$TMP_DIR/eslint-summary.txt" 2>/dev/null | head -n1 | sed 's/[^0-9]//g')
444
+ es_err=${es_err:-0}; es_warn=${es_warn:-0}
445
+
446
+ if [[ -f "$TMP_DIR/ast-summary.json" ]]; then
447
+ if command -v jq >/dev/null 2>&1; then
448
+ crit=$(jq -r '.levels.CRITICAL // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
449
+ high=$(jq -r '.levels.HIGH // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
450
+ med=$(jq -r '.levels.MEDIUM // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
451
+ low=$(jq -r '.levels.LOW // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
452
+ else
453
+ crit=$(grep -o '"CRITICAL"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | head -n1 | sed 's/[^0-9]//g')
454
+ high=$(grep -o '"HIGH"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | head -n1 | sed 's/[^0-9]//g')
455
+ med=$(grep -o '"MEDIUM"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | head -n1 | sed 's/[^0-9]//g')
456
+ low=$(grep -o '"LOW"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | head -n1 | sed 's/[^0-9]//g')
457
+ fi
458
+ crit=${crit:-0}; high=${high:-0}; med=${med:-0}; low=${low:-0}
459
+ else
460
+ crit=0; high=0; med=0; low=0
461
+ fi
462
+
463
+ total_violations=$((crit + high + med + low))
464
+ files_scanned=$(if [[ -f "$TMP_DIR/files.txt" ]]; then wc -l < "$TMP_DIR/files.txt" | tr -d ' '; else echo "0"; fi)
465
+
466
+ # Quick summary header
467
+ printf "%b╔═══════════════════════════════════════════════════════════════╗%b\n" "$BLUE" "$NC"
468
+ printf "%b║ %-61s ║%b\n" "$BLUE" "QUICK SUMMARY" "$NC"
469
+ printf "%b╚═══════════════════════════════════════════════════════════════╝%b\n\n" "$BLUE" "$NC"
470
+
471
+ printf " %bFiles Scanned:%b %s\n" "$BLUE" "$NC" "$files_scanned"
472
+ printf " %bTotal Violations:%b %s\n" "$YELLOW" "$NC" "$total_violations"
473
+ printf " %bESLint Errors:%b %s\n" "$RED" "$NC" "$es_err"
474
+ printf " %bCritical Issues:%b %s\n" "$RED" "$NC" "$crit"
475
+ printf " %bHigh Priority:%b %s\n\n" "$YELLOW" "$NC" "$high"
476
+
477
+ if (( crit > 0 || high > 0 || es_err > 0 )); then
478
+ printf " %b⚠️ STATUS: ACTION REQUIRED%b\n" "$RED" "$NC"
479
+ printf " %b Critical or high-severity issues detected%b\n\n" "$YELLOW" "$NC"
480
+ else
481
+ printf " %b✅ STATUS: ALL CLEAR%b\n" "$GREEN" "$NC"
482
+ printf " %b No critical issues detected%b\n\n" "$GREEN" "$NC"
483
+ fi
484
+
485
+ printf "%b1. PATTERN CHECKS%b\n" "$YELLOW" "$NC"
486
+ printf "─────────────────────────────────────────────────────────────\n"
487
+ local patterns_file="$TMP_DIR/pattern-summary.txt"
488
+ if [[ -f "$patterns_file" ]]; then
489
+ local total_patterns=0
490
+ local has_violations=0
491
+ while IFS=: read -r key val; do
492
+ [[ -z "$key" ]] && continue
493
+ val=${val:-0}
494
+ if [[ $val -gt 0 ]]; then
495
+ has_violations=1
496
+ total_patterns=$((total_patterns + val))
497
+ case "$key" in
498
+ TODO_FIXME) printf " %s %s: %s\n" "$EMJ_WARN" "$key" "$val" ;;
499
+ CONSOLE_LOG) printf " %s %s: %s\n" "$EMJ_WARN" "$key" "$val" ;;
500
+ ANY_TYPE) printf " %s %s: %s\n" "$EMJ_ERR" "$key" "$val" ;;
501
+ SQL_RAW) printf " %s %s: %s\n" "$EMJ_ERR" "$key" "$val" ;;
502
+ HARDCODED_SECRET) printf " %s %s: %s\n" "$EMJ_ERR" "$key" "$val" ;;
503
+ DISABLED_LINT) printf " %s %s: %s\n" "$EMJ_INFO" "$key" "$val" ;;
504
+ *) printf " %s: %s\n" "$key" "$val" ;;
505
+ esac
506
+ fi
507
+ done < "$patterns_file"
508
+ if [[ $has_violations -eq 0 ]]; then
509
+ printf " %b✅ No pattern violations detected%b\n" "$GREEN" "$NC"
510
+ fi
511
+ else
512
+ printf " No pattern summary available.\n"
513
+ fi
514
+
515
+ printf "\n%b2. ESLINT AUDIT RESULTS%b\n" "$YELLOW" "$NC"
516
+ printf "─────────────────────────────────────────────────────────────\n"
517
+ if [[ -f "$TMP_DIR/eslint-summary.txt" ]]; then
518
+ es_err=$(grep -o 'errors=[0-9]\+' "$TMP_DIR/eslint-summary.txt" | head -n1 | sed 's/[^0-9]//g')
519
+ es_warn=$(grep -o 'warnings=[0-9]\+' "$TMP_DIR/eslint-summary.txt" | head -n1 | sed 's/[^0-9]//g')
520
+ es_err=${es_err:-0}; es_warn=${es_warn:-0}
521
+ if [[ $es_err -gt 0 ]]; then
522
+ printf " %bESLint:%b 🔴 errors=%s 🟡 warnings=%s\n" "$RED" "$NC" "$es_err" "$es_warn"
523
+ else
524
+ printf " %bESLint:%b 🔴 errors=%s 🟡 warnings=%s\n" "$GREEN" "$NC" "$es_err" "$es_warn"
525
+ fi
526
+ else
527
+ printf " No ESLint summary available.\n"
528
+ fi
529
+
530
+ if [[ -f "$TMP_DIR/ast-summary.json" ]]; then
531
+ local has_staged="0"
532
+ if [[ -n "${STAGED_CRIT-}" || -s "$TMP_DIR/staged.txt" ]]; then has_staged="1"; fi
533
+
534
+ # Staging Area breakdown (always show section)
535
+ printf "\n%b3. AST INTELLIGENCE - SEVERITY BREAKDOWN (Staging Area)%b\n" "$YELLOW" "$NC"
536
+ printf "─────────────────────────────────────────────────────────────\n"
537
+ if [[ -s "$TMP_DIR/staged.txt" ]]; then
538
+ local scr=${STAGED_CRIT:-0}
539
+ local shi=${STAGED_HIGH:-0}
540
+ local sme=${STAGED_MED:-0}
541
+ local slo=${STAGED_LOW:-0}
542
+ local total_s=$((scr + shi + sme + slo))
543
+ printf " %b🔴 CRITICAL:%b %s violations" "$RED" "$NC" "$scr"; if [[ $total_s -gt 0 ]]; then printf " (%d%%)" $((scr * 100 / total_s)); fi; printf "\n"
544
+ printf " %b🟠 HIGH:%b %s violations" "$YELLOW" "$NC" "$shi"; if [[ $total_s -gt 0 ]]; then printf " (%d%%)" $((shi * 100 / total_s)); fi; printf "\n"
545
+ printf " %b🟡 MEDIUM:%b %s violations" "$YELLOW" "$NC" "$sme"; if [[ $total_s -gt 0 ]]; then printf " (%d%%)" $((sme * 100 / total_s)); fi; printf "\n"
546
+ printf " %b🔵 LOW:%b %s violations" "$BLUE" "$NC" "$slo"; if [[ $total_s -gt 0 ]]; then printf " (%d%%)" $((slo * 100 / total_s)); fi; printf "\n"
547
+ else
548
+ printf " No staged files to analyze.\n"
549
+ fi
550
+
551
+ # Repository breakdown (always)
552
+ printf "\n%b3. AST INTELLIGENCE - SEVERITY BREAKDOWN (Repository)%b\n" "$YELLOW" "$NC"
553
+ printf "─────────────────────────────────────────────────────────────\n"
554
+ local total_r=$((crit + high + med + low))
555
+ printf " %b🔴 CRITICAL:%b %s violations" "$RED" "$NC" "$crit"; if [[ $total_r -gt 0 ]]; then printf " (%d%%)" $((crit * 100 / total_r)); fi; printf "\n"
556
+ printf " %b🟠 HIGH:%b %s violations" "$YELLOW" "$NC" "$high"; if [[ $total_r -gt 0 ]]; then printf " (%d%%)" $((high * 100 / total_r)); fi; printf "\n"
557
+ printf " %b🟡 MEDIUM:%b %s violations" "$YELLOW" "$NC" "$med"; if [[ $total_r -gt 0 ]]; then printf " (%d%%)" $((med * 100 / total_r)); fi; printf "\n"
558
+ printf " %b🔵 LOW:%b %s violations" "$BLUE" "$NC" "$low"; if [[ $total_r -gt 0 ]]; then printf " (%d%%)" $((low * 100 / total_r)); fi; printf "\n"
559
+
560
+ printf "\n%b4. PLATFORM-SPECIFIC ANALYSIS%b\n" "$YELLOW" "$NC"
561
+ printf "─────────────────────────────────────────────────────────────\n"
562
+ if command -v jq >/dev/null 2>&1; then
563
+ print_platform_summary "Backend" "$TMP_DIR/ast-summary.json"
564
+ print_platform_summary "Frontend" "$TMP_DIR/ast-summary.json"
565
+ print_platform_summary "iOS" "$TMP_DIR/ast-summary.json"
566
+ print_platform_summary "Android" "$TMP_DIR/ast-summary.json"
567
+ print_platform_summary "Other" "$TMP_DIR/ast-summary.json"
568
+ else
569
+ local be fe ios android oth
570
+ be=$(grep -o '"Backend"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | sed 's/[^0-9]//g')
571
+ fe=$(grep -o '"Frontend"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | sed 's/[^0-9]//g')
572
+ ios=$(grep -o '"iOS"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | sed 's/[^0-9]//g')
573
+ android=$(grep -o '"Android"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | sed 's/[^0-9]//g')
574
+ oth=$(grep -o '"Other"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | sed 's/[^0-9]//g')
575
+ printf "Backend: %s\n" "${be:-0}"
576
+ printf "Frontend: %s\n" "${fe:-0}"
577
+ printf "iOS: %s\n" "${ios:-0}"
578
+ printf "Android: %s\n" "${android:-0}"
579
+ printf "Other: %s\n" "${oth:-0}"
580
+ fi
581
+
582
+ printf "\n%b5. TOP VIOLATIONS & REMEDIATION%b\n" "$YELLOW" "$NC"
583
+ printf "─────────────────────────────────────────────────────────────\n"
584
+ if command -v jq >/dev/null 2>&1; then
585
+ local jq_cmd violations_output
586
+ jq_cmd=".rules | to_entries | sort_by(-.value) | .[0:10] | .[] | (.key + \":\" + (.value | tostring))"
587
+ violations_output=$(jq -r "$jq_cmd" "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "")
588
+
589
+ if [[ -n "$violations_output" ]]; then
590
+ local rule_count=0
591
+ while IFS=: read -r rule count; do
592
+ if [[ -n "$rule" && -n "$count" && "$count" -gt 0 ]]; then
593
+ rule_count=$((rule_count + 1))
594
+ printf "\n %b🔍 %s%b (%s violations)\n" "$BLUE" "$rule" "$NC" "$count"
595
+ get_recommendation "$rule" "$count" | sed 's/^/ /'
596
+ fi
597
+ done <<< "$violations_output"
598
+
599
+ if [[ $rule_count -eq 0 ]]; then
600
+ printf " %b✅ No violations detected%b\n" "$GREEN" "$NC"
601
+ fi
602
+ else
603
+ printf " %b✅ No violations detected%b\n" "$GREEN" "$NC"
604
+ fi
605
+ else
606
+ printf " Install jq for detailed recommendations.\n"
607
+ fi
608
+
609
+ printf "\n%b6. EXECUTIVE SUMMARY%b\n" "$YELLOW" "$NC"
610
+ printf "─────────────────────────────────────────────────────────────\n"
611
+ # Use variables already defined at the top of the function
612
+ local total_violations=$((crit + high + med + low))
613
+
614
+ printf "\n"
615
+ printf " %b— METRICS —%b\n" "$BLUE" "$NC"
616
+ printf " Total violations detected: %s\n" "$total_violations"
617
+ printf " ESLint errors: %s\n" "$es_err"
618
+ printf " ESLint warnings: %s\n" "$es_warn"
619
+ printf " Critical issues: %s\n" "$crit"
620
+ printf " High priority issues: %s\n" "$high"
621
+ printf " Files scanned: %s\n\n" "$files_scanned"
622
+
623
+ # Calculate code health score (0-100)
624
+ local health_score=100
625
+ if [[ $files_scanned -gt 0 ]]; then
626
+ # Base score: penalize violations per file
627
+ local violations_per_file=$(( total_violations * 100 / files_scanned ))
628
+ if [[ $violations_per_file -gt 100 ]]; then
629
+ violations_per_file=100
630
+ fi
631
+ health_score=$(( 100 - violations_per_file ))
632
+
633
+ # Additional penalties
634
+ if [[ $crit -gt 0 ]]; then
635
+ health_score=$(( health_score - 10 ))
636
+ fi
637
+ if [[ $high -gt 50 ]]; then
638
+ health_score=$(( health_score - 10 ))
639
+ fi
640
+ if [[ $es_err -gt 0 ]]; then
641
+ health_score=$(( health_score - 5 ))
642
+ fi
643
+
644
+ # Ensure score is within bounds
645
+ if [[ $health_score -lt 0 ]]; then
646
+ health_score=0
647
+ fi
648
+ if [[ $health_score -gt 100 ]]; then
649
+ health_score=100
650
+ fi
651
+ fi
652
+
653
+ printf " %bCode Health Score:%b " "$BLUE" "$NC"
654
+ if [[ $health_score -ge 80 ]]; then
655
+ printf "%b%d%% (Excellent)%b\n" "$GREEN" "$health_score" "$NC"
656
+ elif [[ $health_score -ge 60 ]]; then
657
+ printf "%b%d%% (Good)%b\n" "$YELLOW" "$health_score" "$NC"
658
+ elif [[ $health_score -ge 40 ]]; then
659
+ printf "%b%d%% (Needs Improvement)%b\n" "$YELLOW" "$health_score" "$NC"
660
+ else
661
+ printf "%b%d%% (Critical)%b\n" "$RED" "$health_score" "$NC"
662
+ fi
663
+
664
+ printf "\n"
665
+ local gcrit=$crit; local ghigh=$high
666
+ if [[ -n "${STAGED_CRIT-}" ]]; then gcrit=${STAGED_CRIT-0}; fi
667
+ if [[ -n "${STAGED_HIGH-}" ]]; then ghigh=${STAGED_HIGH-0}; fi
668
+ if (( gcrit > 0 || ghigh > 0 || es_err > 0 )); then
669
+ printf " %b╔═══════════════════════════════════════════════════════════════╗%b\n" "$RED" "$NC"
670
+ printf " %b║ %-61s ║%b\n" "$RED" "ACTION REQUIRED: Critical or high-severity issues" "$NC"
671
+ printf " %b║ %-61s ║%b\n" "$RED" "detected. Please review and fix before proceeding." "$NC"
672
+ printf " %b╚═══════════════════════════════════════════════════════════════╝%b\n" "$RED" "$NC"
673
+
674
+ printf "\n %b📋 Quick Actions:%b\n" "$YELLOW" "$NC"
675
+ if [[ $gcrit -gt 0 ]]; then
676
+ printf " 1. Fix %s CRITICAL issues (security, architecture violations)\n" "$gcrit"
677
+ fi
678
+ if [[ $ghigh -gt 0 ]]; then
679
+ printf " 2. Address %s HIGH priority issues (types.any, etc.)\n" "$ghigh"
680
+ fi
681
+ if [[ $es_err -gt 0 ]]; then
682
+ printf " 3. Resolve %s ESLint errors\n" "$es_err"
683
+ fi
684
+ printf " 4. Review top violations section for specific recommendations\n"
685
+ else
686
+ printf " %b✅ No critical issues detected%b\n" "$GREEN" "$NC"
687
+ printf " %b Code quality is within acceptable standards.%b\n" "$GREEN" "$NC"
688
+ fi
689
+ fi
690
+
691
+ local end_time=$(date +%s)
692
+ local elapsed=$(( end_time - START_TIME ))
693
+ printf "\n%b7. AUDIT METADATA%b\n" "$YELLOW" "$NC"
694
+ printf "─────────────────────────────────────────────────────────────\n"
695
+ printf " Elapsed time: %ss\n" "$elapsed"
696
+ printf " Timestamp: %s\n" "$(date '+%Y-%m-%d %H:%M:%S')"
697
+ printf " Files scanned: %s\n" "$(if [[ -f "$TMP_DIR/files.txt" ]]; then wc -l < "$TMP_DIR/files.txt" | tr -d ' '; else echo "0"; fi)"
698
+
699
+ # Re-read final counts for consistency (use same variables as defined earlier)
700
+ local final_crit final_high final_med final_low final_es_err final_es_warn
701
+ if [[ -f "$TMP_DIR/ast-summary.json" ]]; then
702
+ if command -v jq >/dev/null 2>&1; then
703
+ final_crit=$(jq -r '.levels.CRITICAL // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
704
+ final_high=$(jq -r '.levels.HIGH // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
705
+ final_med=$(jq -r '.levels.MEDIUM // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
706
+ final_low=$(jq -r '.levels.LOW // 0' "$TMP_DIR/ast-summary.json" 2>/dev/null || echo "0")
707
+ else
708
+ final_crit=$(grep -o '"CRITICAL"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | head -n1 | sed 's/[^0-9]//g')
709
+ final_high=$(grep -o '"HIGH"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | head -n1 | sed 's/[^0-9]//g')
710
+ final_med=$(grep -o '"MEDIUM"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | head -n1 | sed 's/[^0-9]//g')
711
+ final_low=$(grep -o '"LOW"\s*:\s*[0-9]\+' "$TMP_DIR/ast-summary.json" | head -n1 | sed 's/[^0-9]//g')
712
+ fi
713
+ final_crit=${final_crit:-0}; final_high=${final_high:-0}; final_med=${final_med:-0}; final_low=${final_low:-0}
714
+ else
715
+ final_crit=0; final_high=0; final_med=0; final_low=0
716
+ fi
717
+ final_es_err=$(grep -o 'errors=[0-9]\+' "$TMP_DIR/eslint-summary.txt" 2>/dev/null | head -n1 | sed 's/[^0-9]//g')
718
+ final_es_warn=$(grep -o 'warnings=[0-9]\+' "$TMP_DIR/eslint-summary.txt" 2>/dev/null | head -n1 | sed 's/[^0-9]//g')
719
+ final_es_err=${final_es_err:-0}; final_es_warn=${final_es_warn:-0}
720
+
721
+ # Final summary with emojis before signature
722
+ printf "\n%b═══════════════════════════════════════════════════════════════%b\n" "$BLUE" "$NC"
723
+ printf "%bFINAL SUMMARY - VIOLATIONS BY SEVERITY%b\n" "$BLUE" "$NC"
724
+ printf "%b═══════════════════════════════════════════════════════════════%b\n\n" "$BLUE" "$NC"
725
+
726
+ local final_total=$((final_crit + final_high + final_med + final_low))
727
+ printf " %b🔴 CRITICAL:%b %s\n" "$RED" "$NC" "$final_crit"
728
+ printf " %b🟠 HIGH:%b %s\n" "$YELLOW" "$NC" "$final_high"
729
+ printf " %b🟡 MEDIUM:%b %s\n" "$YELLOW" "$NC" "$final_med"
730
+ printf " %b🔵 LOW:%b %s\n" "$BLUE" "$NC" "$final_low"
731
+ printf "\n Total violations: %s\n" "$final_total"
732
+ if [[ $final_es_err -gt 0 ]]; then
733
+ printf " %bESLint errors:%b %s\n" "$RED" "$NC" "$final_es_err"
734
+ fi
735
+ if [[ $final_es_warn -gt 0 ]]; then
736
+ printf " %bESLint warnings:%b %s\n" "$YELLOW" "$NC" "$final_es_warn"
737
+ fi
738
+
739
+ if [[ "${AUDIT_STRICT:-0}" == "1" ]]; then
740
+ if [[ "${GIT_BYPASS_HOOK:-0}" == "1" ]]; then
741
+ printf "\n%b[COMMIT BYPASSED]%b (GIT_BYPASS_HOOK=1)\n" "$YELLOW" "$NC"
742
+ print_final_signature
743
+ exit 0
744
+ fi
745
+ local gate_crit gate_high gate_med gate_low gate_es
746
+
747
+ # Decide gate values based on mode
748
+ if [[ "${BLOCK_ON_REPO_VIOLATIONS:-0}" == "1" ]]; then
749
+ # OPTION 2: Block if REPO has violations (ultra-strict for CI/CD)
750
+ gate_crit=$final_crit
751
+ gate_high=$final_high
752
+ gate_med=$final_med
753
+ gate_low=$final_low
754
+ gate_es=$final_es_err
755
+ else
756
+ # OPTIONS 3,4: Block only on STAGING violations (dev-friendly)
757
+ gate_crit=${STAGED_CRIT:-0}
758
+ gate_high=${STAGED_HIGH:-0}
759
+ gate_med=${STAGED_MED:-0}
760
+ gate_low=${STAGED_LOW:-0}
761
+ gate_es=0
762
+ fi
763
+
764
+ # Check if we should block on ALL severity levels or just CRITICAL/HIGH
765
+ if [[ "${BLOCK_ALL_SEVERITIES:-0}" == "1" ]]; then
766
+ # Block on ANY violation (CRITICAL + HIGH + MEDIUM + LOW)
767
+ if (( gate_crit > 0 || gate_high > 0 || gate_med > 0 || gate_low > 0 || gate_es > 0 )); then
768
+ printf "\n"
769
+ if [[ "${BLOCK_ON_REPO_VIOLATIONS:-0}" == "1" ]]; then
770
+ printf "%b[COMMIT BLOCKED - STRICT REPO+STAGING]%b\n" "$RED" "$NC"
771
+ printf " CRITICAL violations (repository): %s\n" "$gate_crit"
772
+ printf " HIGH violations (repository): %s\n" "$gate_high"
773
+ printf " MEDIUM violations (repository): %s\n" "$gate_med"
774
+ printf " LOW violations (repository): %s\n" "$gate_low"
775
+ printf " ESLint errors (repository): %s\n" "$gate_es"
776
+ printf " Action: Clean entire repository before committing.\n"
777
+ else
778
+ printf "%b[COMMIT BLOCKED - STRICT STAGING]%b\n" "$RED" "$NC"
779
+ printf " CRITICAL violations in staging: %s\n" "$gate_crit"
780
+ printf " HIGH violations in staging: %s\n" "$gate_high"
781
+ printf " MEDIUM violations in staging: %s\n" "$gate_med"
782
+ printf " LOW violations in staging: %s\n" "$gate_low"
783
+ printf " Action: Fix violations in staged files before committing.\n"
784
+ fi
785
+ printf "\n"
786
+ print_final_signature
787
+ exit 1
788
+ fi
789
+ else
790
+ # Standard mode: Block only on CRITICAL/HIGH IN STAGING
791
+ if (( gate_crit > 0 || gate_high > 0 )); then
792
+ printf "\n"
793
+ printf "%b[COMMIT BLOCKED - CRITICAL/HIGH]%b\n" "$RED" "$NC"
794
+ printf " CRITICAL violations in staging: %s\n" "$gate_crit"
795
+ printf " HIGH violations in staging: %s\n" "$gate_high"
796
+ printf " Action: Fix critical/high violations in staged files before committing.\n"
797
+ printf "\n"
798
+ print_final_signature
799
+ exit 1
800
+ fi
801
+ fi
802
+ fi
803
+
804
+ printf "\n"
805
+ print_final_signature
806
+
807
+ save_audit_reports
808
+ }
809
+
810
+ save_audit_reports() {
811
+ local timestamp=$(date +%Y%m%d_%H%M%S)
812
+ local report_prefix="${REPORTS_DIR}/audit_${timestamp}"
813
+
814
+ if [[ -f "$TMP_DIR/ast-summary.json" ]]; then
815
+ cp "$TMP_DIR/ast-summary.json" "${report_prefix}_ast_summary.json"
816
+ fi
817
+
818
+ if [[ -f "$TMP_DIR/ast-findings.json" ]]; then
819
+ cp "$TMP_DIR/ast-findings.json" "${report_prefix}_ast_findings.json"
820
+ fi
821
+
822
+ if [[ -f "$TMP_DIR/pattern-summary.txt" ]]; then
823
+ cp "$TMP_DIR/pattern-summary.txt" "${report_prefix}_patterns.txt"
824
+ fi
825
+
826
+ if [[ -f "$TMP_DIR/eslint-summary.txt" ]]; then
827
+ cp "$TMP_DIR/eslint-summary.txt" "${report_prefix}_eslint.txt"
828
+ fi
829
+
830
+ local latest_summary="${REPORTS_DIR}/latest_ast_summary.json"
831
+ local latest_findings="${REPORTS_DIR}/latest_ast_findings.json"
832
+ local latest_critical="${REPORTS_DIR}/latest_critical.json"
833
+ local latest_high="${REPORTS_DIR}/latest_high.json"
834
+ local latest_medium="${REPORTS_DIR}/latest_medium.json"
835
+ local latest_low="${REPORTS_DIR}/latest_low.json"
836
+
837
+ if [[ -f "$TMP_DIR/ast-summary.json" ]]; then
838
+ cp "$TMP_DIR/ast-summary.json" "$latest_summary"
839
+ cp "$TMP_DIR/ast-summary.json" "${REPORTS_DIR}/baseline_ast_summary.json"
840
+
841
+ if command -v jq >/dev/null 2>&1; then
842
+ jq '{
843
+ severity: "CRITICAL",
844
+ count: ([.findings[] | select(.severity == "critical" or .severity == "error")] | length),
845
+ findings: [.findings[] | select(.severity == "critical" or .severity == "error") | {
846
+ ruleId,
847
+ file: (.filePath | split("/") | .[-1]),
848
+ fullPath: .filePath,
849
+ line,
850
+ message
851
+ }]
852
+ }' "$TMP_DIR/ast-summary.json" > "$latest_critical" 2>/dev/null || true
853
+
854
+ jq '{
855
+ severity: "HIGH",
856
+ count: ([.findings[] | select(.severity == "high" or .severity == "warning")] | length),
857
+ findings: [.findings[] | select(.severity == "high" or .severity == "warning") | {
858
+ ruleId,
859
+ file: (.filePath | split("/") | .[-1]),
860
+ fullPath: .filePath,
861
+ line,
862
+ message
863
+ }]
864
+ }' "$TMP_DIR/ast-summary.json" > "$latest_high" 2>/dev/null || true
865
+
866
+ jq '{
867
+ severity: "MEDIUM",
868
+ count: ([.findings[] | select(.severity == "medium" or .severity == "info")] | length),
869
+ findings: [.findings[] | select(.severity == "medium" or .severity == "info") | {
870
+ ruleId,
871
+ file: (.filePath | split("/") | .[-1]),
872
+ fullPath: .filePath,
873
+ line,
874
+ message
875
+ }]
876
+ }' "$TMP_DIR/ast-summary.json" > "$latest_medium" 2>/dev/null || true
877
+
878
+ jq '{
879
+ severity: "LOW",
880
+ count: ([.findings[] | select(.severity == "low" or .severity == "note")] | length),
881
+ findings: [.findings[] | select(.severity == "low" or .severity == "note") | {
882
+ ruleId,
883
+ file: (.filePath | split("/") | .[-1]),
884
+ fullPath: .filePath,
885
+ line,
886
+ message
887
+ }]
888
+ }' "$TMP_DIR/ast-summary.json" > "$latest_low" 2>/dev/null || true
889
+ fi
890
+ fi
891
+ if [[ -f "$TMP_DIR/ast-findings.json" ]]; then
892
+ cp "$TMP_DIR/ast-findings.json" "$latest_findings"
893
+ fi
894
+ }
895
+
896
+ export_markdown() {
897
+ local out="${TMP_DIR}/audit-report.md"
898
+ printf "# Audit Report\n\n" > "$out"
899
+ printf "## %s\n\n" "$MSG_SUMMARY" >> "$out"
900
+ if [[ -f "${TMP_DIR}/pattern-summary.txt" ]]; then
901
+ cat "${TMP_DIR}/pattern-summary.txt" >> "$out"
902
+ printf "\n" >> "$out"
903
+ fi
904
+ if [[ -f "${TMP_DIR}/eslint-summary.txt" ]]; then
905
+ cat "${TMP_DIR}/eslint-summary.txt" >> "$out"
906
+ printf "\n" >> "$out"
907
+ fi
908
+ printf "%s %s\n" "$EMJ_OK" "$out"
909
+ }
910
+
911
+ run_ast_intelligence() {
912
+ printf "%b⚙️ AST Intelligence%b\n" "$YELLOW" "$NC"
913
+ printf "%bRunning AST analysis...%b " "$YELLOW" "$NC" >&2
914
+
915
+ # Capture AST output and format it better
916
+ local ast_output
917
+ local ast_exit_code=0
918
+
919
+ # Ensure TMP_DIR exists
920
+ mkdir -p "$TMP_DIR"
921
+
922
+ local node_bin=""
923
+ node_bin="$(command -v node 2>/dev/null || true)"
924
+ if [[ -z "$node_bin" ]]; then
925
+ if [[ -x "/opt/homebrew/bin/node" ]]; then node_bin="/opt/homebrew/bin/node"; fi
926
+ fi
927
+ if [[ -z "$node_bin" ]]; then
928
+ if [[ -x "/usr/local/bin/node" ]]; then node_bin="/usr/local/bin/node"; fi
929
+ fi
930
+ if [[ -z "$node_bin" ]]; then
931
+ if [[ -x "/usr/bin/node" ]]; then node_bin="/usr/bin/node"; fi
932
+ fi
933
+ if [[ -z "$node_bin" ]]; then
934
+ local nvm_dir="${NVM_DIR:-$HOME/.nvm}"
935
+ local nvm_default=""
936
+ if [[ -f "$nvm_dir/alias/default" ]]; then
937
+ nvm_default="$(cat "$nvm_dir/alias/default" 2>/dev/null || true)"
938
+ nvm_default="${nvm_default##v}"
939
+ nvm_default="${nvm_default%%[[:space:]]*}"
940
+ fi
941
+ if [[ -n "$nvm_default" ]] && [[ -x "$nvm_dir/versions/node/v${nvm_default}/bin/node" ]]; then
942
+ node_bin="$nvm_dir/versions/node/v${nvm_default}/bin/node"
943
+ fi
944
+ fi
945
+ if [[ -z "$node_bin" ]]; then
946
+ local nvm_dir_fallback="${NVM_DIR:-$HOME/.nvm}"
947
+ local latest_node=""
948
+ latest_node="$(ls -1 "$nvm_dir_fallback/versions/node" 2>/dev/null | grep -E '^v[0-9]+' | sort -V | tail -n 1 || true)"
949
+ if [[ -n "$latest_node" ]] && [[ -x "$nvm_dir_fallback/versions/node/${latest_node}/bin/node" ]]; then
950
+ node_bin="$nvm_dir_fallback/versions/node/${latest_node}/bin/node"
951
+ fi
952
+ fi
953
+ if [[ -z "$node_bin" ]]; then
954
+ 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
955
+ return 127
956
+ fi
957
+
958
+ # Determine NODE_PATH to include library's node_modules
959
+ # Try multiple locations: HOOKS_SYSTEM_DIR/node_modules, or project root node_modules
960
+ local -a node_path_parts
961
+ node_path_parts=()
962
+
963
+ # If HOOKS_SYSTEM_DIR has its own node_modules
964
+ if [[ -d "$HOOKS_SYSTEM_DIR/node_modules" ]]; then
965
+ node_path_parts+=("$HOOKS_SYSTEM_DIR/node_modules")
966
+ fi
967
+
968
+ # Also check if we're in a project with node_modules/@pumuki/ast-intelligence-hooks
969
+ local repo_root=""
970
+ if [[ "$HOOKS_SYSTEM_DIR" == *"scripts/hooks-system"* ]]; then
971
+ # Running from scripts/hooks-system, go to repo root
972
+ repo_root="$(cd "$HOOKS_SYSTEM_DIR/../.." && pwd)"
973
+ elif [[ "$HOOKS_SYSTEM_DIR" == *"node_modules/@pumuki/ast-intelligence-hooks"* ]]; then
974
+ # Running from node_modules, go to repo root
975
+ repo_root="$(cd "$HOOKS_SYSTEM_DIR/../../.." && pwd)"
976
+ else
977
+ # Try current directory
978
+ repo_root="$(pwd)"
979
+ fi
980
+
981
+ if [[ -n "$repo_root" ]] && [[ -d "$repo_root/node_modules/@pumuki/ast-intelligence-hooks/node_modules" ]]; then
982
+ node_path_parts+=("$repo_root/node_modules/@pumuki/ast-intelligence-hooks/node_modules")
983
+ fi
984
+
985
+ if [[ -n "$repo_root" ]] && [[ -d "$repo_root/node_modules" ]]; then
986
+ node_path_parts+=("$repo_root/node_modules")
987
+ fi
988
+
989
+ # Build NODE_PATH
990
+ local node_path_value="${NODE_PATH:-}"
991
+ for path_part in "${node_path_parts[@]:-}"; do
992
+ if [[ -n "$node_path_value" ]]; then
993
+ node_path_value="$path_part:$node_path_value"
994
+ else
995
+ node_path_value="$path_part"
996
+ fi
997
+ done
998
+
999
+ # Execute AST with proper error handling and NODE_PATH
1000
+ # Change to HOOKS_SYSTEM_DIR so Node.js resolves modules correctly
1001
+ if [[ -n "$node_path_value" ]]; then
1002
+ ast_output=$(cd "$HOOKS_SYSTEM_DIR" && export NODE_PATH="$node_path_value" && export AUDIT_TMP="$TMP_DIR" && "$node_bin" "${AST_DIR}/ast-intelligence.js" 2>&1) || ast_exit_code=$?
1003
+ else
1004
+ ast_output=$(cd "$HOOKS_SYSTEM_DIR" && export AUDIT_TMP="$TMP_DIR" && "$node_bin" "${AST_DIR}/ast-intelligence.js" 2>&1) || ast_exit_code=$?
1005
+ fi
1006
+
1007
+ # Check if AST script failed
1008
+ if [[ $ast_exit_code -ne 0 ]]; then
1009
+ printf "%b⚠️ AST Intelligence encountered errors (exit code: $ast_exit_code)%b\n" "$YELLOW" "$NC"
1010
+ printf "%bOutput:%b\n%s\n" "$YELLOW" "$NC" "$ast_output"
1011
+ fi
1012
+
1013
+ # Verify JSON file was created
1014
+ if [[ ! -f "$TMP_DIR/ast-summary.json" ]]; then
1015
+ printf "%b⚠️ AST summary JSON not found - AST may have failed%b\n" "$RED" "$NC"
1016
+ printf "%bDebug info:%b\n" "$YELLOW" "$NC"
1017
+ printf " AST script: %s\n" "${AST_DIR}/ast-intelligence.js"
1018
+ printf " Output dir: %s\n" "$TMP_DIR"
1019
+ printf " AST output preview:\n%s\n" "$(echo "$ast_output" | head -20)"
1020
+ return 1
1021
+ fi
1022
+
1023
+ # Processing AST findings
1024
+ printf "%bProcessing AST findings...%b\n" "$YELLOW" "$NC"
1025
+
1026
+ # Show raw output for debugging (first 20 lines)
1027
+ if [[ "${DEBUG_AST:-0}" == "1" ]]; then
1028
+ printf "%bDebug - AST output:%b\n%s\n" "$BLUE" "$NC" "$(echo "$ast_output" | head -20)"
1029
+ printf "%bDebug - JSON file exists:%b %s\n" "$BLUE" "$NC" "$([ -f "$TMP_DIR/ast-summary.json" ] && echo "YES" || echo "NO")"
1030
+ if [[ -f "$TMP_DIR/ast-summary.json" ]]; then
1031
+ printf "%bDebug - JSON preview:%b\n%s\n" "$BLUE" "$NC" "$(head -30 "$TMP_DIR/ast-summary.json")"
1032
+ fi
1033
+ fi
1034
+
1035
+ local violation_count=0
1036
+ while IFS= read -r line; do
1037
+ if [[ "$line" =~ ^AST\ Intelligence ]]; then
1038
+ printf " %s\n" "$line"
1039
+ elif [[ "$line" =~ ^(🔴|🟡|🔵|🟠) ]]; then
1040
+ violation_count=$((violation_count + 1))
1041
+ if [[ $violation_count -le 10 ]]; then
1042
+ printf " %s\n" "$line"
1043
+ fi
1044
+ elif [[ "$line" =~ ^AST\ Totals ]]; then
1045
+ printf " %b%s%b\n" "$GREEN" "$line" "$NC"
1046
+ elif [[ "$line" =~ ^AST\ SUMMARY ]]; then
1047
+ # Skip summary lines, they're already parsed from JSON
1048
+ continue
1049
+ fi
1050
+ done < <(echo "$ast_output" | grep -E "^(🔴|🟡|🔵|🟠|AST Intelligence|AST Totals|AST SUMMARY)" || true)
1051
+
1052
+ if [[ $violation_count -gt 10 ]]; then
1053
+ printf " ... and %d more violations (see ast-summary.json for details)\n" $((violation_count - 10))
1054
+ fi
1055
+
1056
+ printf "%b✅ AST Intelligence completed%b\n\n" "$GREEN" "$NC"
1057
+ }
1058
+
1059
+ interactive_menu() {
1060
+ print_header
1061
+ PS3="Choose an option: "
1062
+ select opt in "Full audit (repo analysis)" "Strict REPO+STAGING (CI/CD)" "Strict STAGING only (dev)" "Standard CRITICAL/HIGH" "Pattern checks" "ESLint Admin+Web" "AST Intelligence" "Export Markdown" "Exit"; do
1063
+ case $REPLY in
1064
+ 1) full_audit; break ;;
1065
+ 2) full_audit_strict_repo_and_staging; break ;;
1066
+ 3) full_audit_strict_staging_only; break ;;
1067
+ 4) full_audit_standard; break ;;
1068
+ 5) print_header; run_basic_checks; summarize_all; break ;;
1069
+ 6) print_header; run_eslint_suite; summarize_all; break ;;
1070
+ 7) print_header; run_ast_intelligence; break ;;
1071
+ 8) export_markdown; break ;;
1072
+ 9) printf "%s\n" "$MSG_BYE"; exit 0 ;;
1073
+ *)
1074
+ if [[ -t 0 ]]; then
1075
+ printf "Invalid option\n"
1076
+ else
1077
+ print_header
1078
+ full_audit_strict_repo_and_staging
1079
+ exit $?
1080
+ fi
1081
+ ;;
1082
+ esac
1083
+ done
1084
+ }
1085
+
1086
+ # Non-interactive mode: if AUDIT_OPTION is set, execute directly
1087
+ if [[ -n "${AUDIT_OPTION:-}" ]]; then
1088
+ case "$AUDIT_OPTION" in
1089
+ 1) print_header; full_audit; exit $? ;;
1090
+ 2) print_header; full_audit_strict_repo_and_staging; exit $? ;;
1091
+ 3) print_header; full_audit_strict_staging_only; exit $? ;;
1092
+ 4) print_header; full_audit_standard; exit $? ;;
1093
+ 5) print_header; run_basic_checks; summarize_all; exit $? ;;
1094
+ 6) print_header; run_eslint_suite; summarize_all; exit $? ;;
1095
+ 7) print_header; run_ast_intelligence; exit $? ;;
1096
+ 8) export_markdown; exit $? ;;
1097
+ 9) exit 0 ;;
1098
+ *)
1099
+ printf "%bInvalid AUDIT_OPTION: %s%b\n" "$RED" "$AUDIT_OPTION" "$NC"
1100
+ exit 1
1101
+ ;;
1102
+ esac
1103
+ fi
1104
+
1105
+ # Fallback: interactive menu para uso humano
1106
+ interactive_menu