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,894 @@
1
+
2
+ const { execSync } = require('child_process');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ class iOSASTIntelligentAnalyzer {
7
+ constructor(findings) {
8
+ this.findings = findings;
9
+ this.sourceKittenPath = '/opt/homebrew/bin/sourcekitten';
10
+ this.isAvailable = this.checkSourceKitten();
11
+ this.hasSwiftSyntax = this.checkSwiftSyntax();
12
+ this.fileContent = '';
13
+ this.currentFilePath = '';
14
+ this.godClassCandidates = [];
15
+ this.allNodes = [];
16
+ this.imports = [];
17
+ this.classes = [];
18
+ this.structs = [];
19
+ this.protocols = [];
20
+ this.functions = [];
21
+ this.properties = [];
22
+ this.closures = [];
23
+ }
24
+
25
+ checkSourceKitten() {
26
+ try {
27
+ execSync(`${this.sourceKittenPath} version`, { stdio: 'pipe' });
28
+ return true;
29
+ } catch {
30
+ return false;
31
+ }
32
+ }
33
+
34
+ checkSwiftSyntax() {
35
+ const projectRoot = require('child_process')
36
+ .execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' })
37
+ .trim();
38
+
39
+ const possiblePaths = [
40
+ path.join(__dirname, '../../../../../CustomLintRules/.build/debug/swift-ast-analyzer'),
41
+ path.join(projectRoot, 'CustomLintRules/.build/debug/swift-ast-analyzer'),
42
+ path.join(projectRoot, '.build/debug/swift-ast-analyzer')
43
+ ];
44
+ for (const p of possiblePaths) {
45
+ if (fs.existsSync(p)) {
46
+ this.swiftSyntaxPath = p;
47
+ return true;
48
+ }
49
+ }
50
+ return false;
51
+ }
52
+
53
+ analyzeWithSwiftSyntax(filePath) {
54
+ if (!this.swiftSyntaxPath) return;
55
+ try {
56
+ const result = execSync(`"${this.swiftSyntaxPath}" "${filePath}"`, {
57
+ encoding: 'utf8', timeout: 30000, stdio: ['pipe', 'pipe', 'pipe']
58
+ });
59
+ const violations = JSON.parse(result);
60
+ for (const v of violations) {
61
+ this.findings.push({
62
+ ruleId: v.ruleId, severity: v.severity, filePath,
63
+ line: v.line, column: v.column, message: v.message
64
+ });
65
+ }
66
+ } catch (error) {
67
+ console.error('[iOSASTIntelligentAnalyzer] Error parsing file:', error.message);
68
+ }
69
+ }
70
+
71
+ parseFile(filePath) {
72
+ if (!this.isAvailable) return null;
73
+ try {
74
+ const result = execSync(
75
+ `${this.sourceKittenPath} structure --file "${filePath}"`,
76
+ { encoding: 'utf8', timeout: 30000, stdio: ['pipe', 'pipe', 'pipe'] }
77
+ );
78
+ return JSON.parse(result);
79
+ } catch {
80
+ return null;
81
+ }
82
+ }
83
+
84
+ analyzeFile(filePath) {
85
+ if (!filePath.endsWith('.swift')) return;
86
+
87
+ if (this.hasSwiftSyntax) {
88
+ this.analyzeWithSwiftSyntax(filePath);
89
+ }
90
+
91
+ const ast = this.parseFile(filePath);
92
+ if (!ast) return;
93
+
94
+ this.currentFilePath = filePath;
95
+ this.resetCollections();
96
+
97
+ try {
98
+ this.fileContent = fs.readFileSync(filePath, 'utf8');
99
+ } catch {
100
+ this.fileContent = '';
101
+ }
102
+
103
+ const substructure = ast['key.substructure'] || [];
104
+
105
+ this.collectAllNodes(substructure, null);
106
+ this.analyzeCollectedNodes(filePath);
107
+ }
108
+
109
+ resetCollections() {
110
+ this.allNodes = [];
111
+ this.imports = [];
112
+ this.classes = [];
113
+ this.structs = [];
114
+ this.protocols = [];
115
+ this.functions = [];
116
+ this.properties = [];
117
+ this.closures = [];
118
+ }
119
+
120
+ collectAllNodes(nodes, parent) {
121
+ if (!Array.isArray(nodes)) return;
122
+
123
+ for (const node of nodes) {
124
+ const kind = node['key.kind'] || '';
125
+ node._parent = parent;
126
+ this.allNodes.push(node);
127
+
128
+ if (kind === 'source.lang.swift.decl.class') {
129
+ this.classes.push(node);
130
+ } else if (kind === 'source.lang.swift.decl.struct') {
131
+ this.structs.push(node);
132
+ } else if (kind === 'source.lang.swift.decl.protocol') {
133
+ this.protocols.push(node);
134
+ } else if (kind.includes('function')) {
135
+ this.functions.push(node);
136
+ } else if (kind.includes('var')) {
137
+ this.properties.push(node);
138
+ } else if (kind.includes('closure')) {
139
+ this.closures.push(node);
140
+ }
141
+
142
+ this.collectAllNodes(node['key.substructure'] || [], node);
143
+ }
144
+ }
145
+
146
+ analyzeCollectedNodes(filePath) {
147
+ this.extractImports();
148
+
149
+ this.analyzeImportsAST(filePath);
150
+
151
+ for (const cls of this.classes) {
152
+ this.analyzeClassAST(cls, filePath);
153
+ }
154
+
155
+ for (const struct of this.structs) {
156
+ this.analyzeStructAST(struct, filePath);
157
+ }
158
+
159
+ for (const proto of this.protocols) {
160
+ this.analyzeProtocolAST(proto, filePath);
161
+ }
162
+
163
+ for (const func of this.functions) {
164
+ this.analyzeFunctionAST(func, filePath);
165
+ }
166
+
167
+ for (const prop of this.properties) {
168
+ this.analyzePropertyAST(prop, filePath);
169
+ }
170
+
171
+ this.analyzeClosuresAST(filePath);
172
+ this.analyzeCleanArchitectureAST(filePath);
173
+ this.analyzeAdditionalRules(filePath);
174
+ }
175
+
176
+ extractImports() {
177
+ const lines = this.fileContent.split('\n');
178
+ for (let i = 0; i < lines.length; i++) {
179
+ const line = lines[i].trim();
180
+ if (line.startsWith('import ')) {
181
+ this.imports.push({
182
+ name: line.replace('import ', '').trim(),
183
+ line: i + 1
184
+ });
185
+ }
186
+ }
187
+ }
188
+
189
+ analyzeImportsAST(filePath) {
190
+ const importNames = this.imports.map(i => i.name);
191
+
192
+ const hasUIKit = importNames.includes('UIKit');
193
+ const hasSwiftUI = importNames.includes('SwiftUI');
194
+ const hasCombine = importNames.includes('Combine');
195
+
196
+ if (hasUIKit && hasSwiftUI) {
197
+ this.pushFinding('ios.architecture.mixed_ui_frameworks', 'medium', filePath, 1,
198
+ 'Mixing UIKit and SwiftUI - consider separating concerns');
199
+ }
200
+
201
+ const hasAsyncFunction = this.functions.some(f =>
202
+ this.hasAttribute(f, 'async')
203
+ );
204
+
205
+ if (hasCombine && !hasAsyncFunction) {
206
+ this.pushFinding('ios.concurrency.combine_without_async', 'low', filePath, 1,
207
+ 'Using Combine - consider async/await for simpler async code');
208
+ }
209
+
210
+ for (const imp of this.imports) {
211
+ if (['Foundation', 'SwiftUI', 'UIKit', 'Combine'].includes(imp.name)) continue;
212
+
213
+ const isUsed = this.allNodes.some(n => {
214
+ const typename = n['key.typename'] || '';
215
+ const name = n['key.name'] || '';
216
+ return typename.includes(imp.name) || name.includes(imp.name);
217
+ });
218
+
219
+ if (!isUsed) {
220
+ this.pushFinding('ios.imports.unused', 'low', filePath, imp.line,
221
+ `Unused import: ${imp.name}`);
222
+ }
223
+ }
224
+
225
+ if (filePath.includes('/Domain/') && (hasUIKit || hasSwiftUI)) {
226
+ this.pushFinding('ios.architecture.domain_ui_import', 'critical', filePath, 1,
227
+ 'Domain layer imports UI framework - violates Clean Architecture');
228
+ }
229
+ }
230
+
231
+ analyzeClassAST(node, filePath) {
232
+ const name = node['key.name'] || '';
233
+ const line = node['key.line'] || 1;
234
+ const bodyLength = node['key.bodylength'] || 0;
235
+ const substructure = node['key.substructure'] || [];
236
+ const inheritedTypes = (node['key.inheritedtypes'] || []).map(t => t['key.name']);
237
+ const attributes = this.getAttributes(node);
238
+
239
+ const methods = substructure.filter(n => (n['key.kind'] || '').includes('function'));
240
+ const properties = substructure.filter(n => (n['key.kind'] || '').includes('var'));
241
+ const inits = methods.filter(m => (m['key.name'] || '').startsWith('init'));
242
+
243
+ if (name && !/Spec$|Test$|Mock/.test(name)) {
244
+ const complexity = this.calculateComplexityAST(substructure);
245
+ this.godClassCandidates.push({
246
+ name,
247
+ filePath,
248
+ line,
249
+ methodsCount: methods.length,
250
+ propertiesCount: properties.length,
251
+ bodyLength,
252
+ complexity,
253
+ });
254
+ }
255
+
256
+ if (name.includes('ViewController')) {
257
+ if (bodyLength > 250 || methods.length > 8) {
258
+ this.pushFinding('ios.architecture.massive_viewcontroller', 'high', filePath, line,
259
+ `Massive ViewController '${name}': ${bodyLength} lines - extract to ViewModel`);
260
+ }
261
+
262
+ const hasBusinessLogic = methods.some(m => {
263
+ const methodName = m['key.name'] || '';
264
+ return /calculate|process|validate|fetch|save|delete|update/i.test(methodName);
265
+ });
266
+
267
+ if (hasBusinessLogic) {
268
+ this.pushFinding('ios.architecture.vc_business_logic', 'high', filePath, line,
269
+ `ViewController '${name}' contains business logic - move to UseCase`);
270
+ }
271
+ }
272
+
273
+ if (name.includes('ViewModel')) {
274
+ const hasMainActor = attributes.includes('MainActor');
275
+ if (!hasMainActor) {
276
+ this.pushFinding('ios.concurrency.viewmodel_mainactor', 'high', filePath, line,
277
+ `ViewModel '${name}' should be @MainActor for UI safety`);
278
+ }
279
+
280
+ const hasObservable = inheritedTypes.includes('ObservableObject') ||
281
+ attributes.includes('Observable');
282
+ if (!hasObservable) {
283
+ this.pushFinding('ios.swiftui.viewmodel_observable', 'medium', filePath, line,
284
+ `ViewModel '${name}' should conform to ObservableObject`);
285
+ }
286
+
287
+ if (inits.length === 0 && properties.length > 0) {
288
+ this.pushFinding('ios.architecture.viewmodel_no_di', 'high', filePath, line,
289
+ `ViewModel '${name}' has no init - use dependency injection`);
290
+ }
291
+ }
292
+
293
+ if (/Manager$|Helper$|Utils$|Handler$/.test(name)) {
294
+ this.pushFinding('ios.naming.god_naming', 'medium', filePath, line,
295
+ `Suspicious class name '${name}' - often indicates SRP violation`);
296
+ }
297
+
298
+ const unusedProps = this.findUnusedPropertiesAST(properties, methods);
299
+ for (const prop of unusedProps) {
300
+ this.pushFinding('ios.solid.isp.unused_dependency', 'high', filePath, line,
301
+ `Unused property '${prop}' in '${name}' - ISP violation`);
302
+ }
303
+
304
+ this.checkDependencyInjectionAST(properties, filePath, name, line);
305
+
306
+ const hasDeinit = methods.some(m => m['key.name'] === 'deinit');
307
+ const hasObservers = this.closures.some(c => c._parent === node) ||
308
+ properties.some(p => this.hasAttribute(p, 'Published'));
309
+
310
+ if (!hasDeinit && hasObservers && !name.includes('ViewModel')) {
311
+ this.pushFinding('ios.memory.missing_deinit', 'high', filePath, line,
312
+ `Class '${name}' has observers but no deinit - potential memory leak`);
313
+ }
314
+
315
+ const isFinal = attributes.includes('final');
316
+ if (!isFinal && inheritedTypes.length === 0 && name !== 'AppDelegate') {
317
+ this.pushFinding('ios.performance.non_final_class', 'low', filePath, line,
318
+ `Class '${name}' is not final - consider final for performance`);
319
+ }
320
+
321
+ const hasSingleton = properties.some(p => {
322
+ const propName = p['key.name'] || '';
323
+ const isStatic = (p['key.kind'] || '').includes('static');
324
+ return isStatic && propName === 'shared';
325
+ });
326
+
327
+ if (hasSingleton) {
328
+ this.pushFinding('ios.antipattern.singleton', 'high', filePath, line,
329
+ `Singleton pattern in '${name}' - use dependency injection`);
330
+ }
331
+
332
+ if (filePath.includes('Test') && name.includes('Test')) {
333
+ const hasMakeSUT = methods.some(m => (m['key.name'] || '').includes('makeSUT'));
334
+ if (!hasMakeSUT && methods.length > 2) {
335
+ this.pushFinding('ios.testing.missing_makesut', 'medium', filePath, line,
336
+ `Test class '${name}' missing makeSUT() factory`);
337
+ }
338
+ }
339
+
340
+ if (name.includes('Repository') && !name.includes('Protocol')) {
341
+ const hasProtocol = inheritedTypes.some(t => t.includes('Protocol'));
342
+ if (!hasProtocol && !filePath.includes('/Domain/')) {
343
+ this.pushFinding('ios.architecture.repository_no_protocol', 'high', filePath, line,
344
+ `Repository '${name}' should implement a protocol`);
345
+ }
346
+ }
347
+
348
+ if (name.includes('UseCase')) {
349
+ const hasExecute = methods.some(m => (m['key.name'] || '').includes('execute'));
350
+ if (!hasExecute) {
351
+ this.pushFinding('ios.architecture.usecase_no_execute', 'medium', filePath, line,
352
+ `UseCase '${name}' missing execute() method`);
353
+ }
354
+ }
355
+ }
356
+
357
+ analyzeStructAST(node, filePath) {
358
+ const name = node['key.name'] || '';
359
+ const line = node['key.line'] || 1;
360
+ const substructure = node['key.substructure'] || [];
361
+ const inheritedTypes = (node['key.inheritedtypes'] || []).map(t => t['key.name']);
362
+
363
+ const methods = substructure.filter(n => (n['key.kind'] || '').includes('function'));
364
+ const properties = substructure.filter(n => (n['key.kind'] || '').includes('var'));
365
+
366
+ if (inheritedTypes.includes('View')) {
367
+ this.analyzeSwiftUIViewAST(node, filePath, name, line, methods, properties);
368
+ }
369
+
370
+ if (inheritedTypes.includes('Codable') || inheritedTypes.includes('Decodable')) {
371
+ const hasOptionalProps = properties.some(p => (p['key.typename'] || '').includes('?'));
372
+ const hasCodingKeys = substructure.some(n => n['key.name'] === 'CodingKeys');
373
+
374
+ if (hasOptionalProps && !hasCodingKeys) {
375
+ this.pushFinding('ios.codable.missing_coding_keys', 'low', filePath, line,
376
+ `Struct '${name}' has optional properties - consider CodingKeys`);
377
+ }
378
+ }
379
+
380
+ if ((inheritedTypes.includes('Equatable') || inheritedTypes.includes('Hashable')) &&
381
+ properties.length > 5) {
382
+ this.pushFinding('ios.performance.large_equatable', 'low', filePath, line,
383
+ `Struct '${name}' has ${properties.length} properties with Equatable`);
384
+ }
385
+ }
386
+
387
+ analyzeSwiftUIViewAST(node, filePath, name, line, methods, properties) {
388
+ const bodyMethod = methods.find(m => m['key.name'] === 'body');
389
+ if (bodyMethod) {
390
+ const bodyLength = bodyMethod['key.bodylength'] || 0;
391
+ if (bodyLength > 100) {
392
+ this.pushFinding('ios.swiftui.complex_body', 'high', filePath, line,
393
+ `View '${name}' has complex body (${bodyLength} lines) - extract subviews`);
394
+ }
395
+ }
396
+
397
+ const stateProps = properties.filter(p =>
398
+ this.hasAttribute(p, 'State') || this.hasAttribute(p, 'Binding')
399
+ );
400
+
401
+ if (stateProps.length > 5) {
402
+ this.pushFinding('ios.swiftui.too_many_state', 'medium', filePath, line,
403
+ `View '${name}' has ${stateProps.length} @State/@Binding - consider ViewModel`);
404
+ }
405
+
406
+ const hasObservedObject = properties.some(p => this.hasAttribute(p, 'ObservedObject'));
407
+ const hasStateObject = properties.some(p => this.hasAttribute(p, 'StateObject'));
408
+
409
+ if (hasObservedObject && !hasStateObject) {
410
+ this.pushFinding('ios.swiftui.observed_without_state', 'medium', filePath, line,
411
+ `View '${name}' uses @ObservedObject - consider @StateObject for ownership`);
412
+ }
413
+ }
414
+
415
+ analyzeProtocolAST(node, filePath) {
416
+ const name = node['key.name'] || '';
417
+ const line = node['key.line'] || 1;
418
+ const substructure = node['key.substructure'] || [];
419
+
420
+ const requirements = substructure.filter(n =>
421
+ (n['key.kind'] || '').includes('function') || (n['key.kind'] || '').includes('var')
422
+ );
423
+
424
+ if (requirements.length > 5) {
425
+ this.pushFinding('ios.solid.isp.fat_protocol', 'medium', filePath, line,
426
+ `Protocol '${name}' has ${requirements.length} requirements - consider splitting (ISP)`);
427
+ }
428
+ }
429
+
430
+ analyzeFunctionAST(node, filePath) {
431
+ const name = node['key.name'] || '';
432
+ const line = node['key.line'] || 1;
433
+ const bodyLength = node['key.bodylength'] || 0;
434
+ const attributes = this.getAttributes(node);
435
+ const substructure = node['key.substructure'] || [];
436
+
437
+ if (bodyLength > 50) {
438
+ this.pushFinding('ios.quality.long_function', 'high', filePath, line,
439
+ `Function '${name}' is too long (${bodyLength} lines)`);
440
+ }
441
+
442
+ const complexity = this.calculateComplexityAST(substructure);
443
+ if (complexity > 10) {
444
+ this.pushFinding('ios.quality.high_complexity', 'high', filePath, line,
445
+ `Function '${name}' has high complexity (${complexity})`);
446
+ }
447
+
448
+ const params = substructure.filter(n => (n['key.kind'] || '').includes('var.parameter'));
449
+ if (params.length > 5) {
450
+ this.pushFinding('ios.quality.too_many_params', 'medium', filePath, line,
451
+ `Function '${name}' has ${params.length} parameters - use struct`);
452
+ }
453
+
454
+ const closuresInFunc = this.countClosuresInNode(node);
455
+ if (closuresInFunc > 3) {
456
+ this.pushFinding('ios.quality.nested_closures', 'medium', filePath, line,
457
+ `Function '${name}' has ${closuresInFunc} nested closures - use async/await`);
458
+ }
459
+
460
+ const ifStatements = this.countStatementsOfType(substructure, 'stmt.if');
461
+ const guardStatements = this.countStatementsOfType(substructure, 'stmt.guard');
462
+
463
+ if (ifStatements > 3 && guardStatements === 0) {
464
+ this.pushFinding('ios.quality.pyramid_of_doom', 'medium', filePath, line,
465
+ `Function '${name}' has ${ifStatements} nested ifs - use guard clauses`);
466
+ }
467
+
468
+ const isAsync = attributes.includes('async');
469
+ const parentClass = node._parent;
470
+ const parentIsView = parentClass &&
471
+ (parentClass['key.inheritedtypes'] || []).some(t => t['key.name'] === 'View');
472
+
473
+ if (isAsync && parentIsView && !attributes.includes('MainActor')) {
474
+ this.pushFinding('ios.concurrency.async_ui_update', 'high', filePath, line,
475
+ `Async function '${name}' in View - consider @MainActor`);
476
+ }
477
+ }
478
+
479
+ analyzePropertyAST(node, filePath) {
480
+ const name = node['key.name'] || '';
481
+ const line = node['key.line'] || 1;
482
+ const typename = node['key.typename'] || '';
483
+ const attributes = this.getAttributes(node);
484
+ const kind = node['key.kind'] || '';
485
+
486
+ if (typename.includes('!') && !attributes.includes('IBOutlet')) {
487
+ this.pushFinding('ios.safety.force_unwrap_property', 'high', filePath, line,
488
+ `Force unwrapped property '${name}: ${typename}'`);
489
+ }
490
+
491
+ const isPublic = (node['key.accessibility'] || '').includes('public');
492
+ const isInstance = kind.includes('var.instance');
493
+
494
+ if (isPublic && isInstance && !attributes.includes('setter_access')) {
495
+ this.pushFinding('ios.encapsulation.public_mutable', 'medium', filePath, line,
496
+ `Public mutable property '${name}' - consider private(set)`);
497
+ }
498
+ }
499
+
500
+ safeStringify(obj) {
501
+ const seen = new WeakSet();
502
+ return JSON.stringify(obj, (key, value) => {
503
+ if (key === '_parent') return undefined;
504
+ if (typeof value === 'object' && value !== null) {
505
+ if (seen.has(value)) return undefined;
506
+ seen.add(value);
507
+ }
508
+ return value;
509
+ });
510
+ }
511
+
512
+ analyzeClosuresAST(filePath) {
513
+ for (const closure of this.closures) {
514
+ const closureText = this.safeStringify(closure);
515
+ const hasSelfReference = closureText.includes('"self"') ||
516
+ closureText.includes('key.name":"self');
517
+
518
+ const parentFunc = closure._parent;
519
+ const isEscaping = parentFunc &&
520
+ (parentFunc['key.typename'] || '').includes('@escaping');
521
+
522
+ if (hasSelfReference && isEscaping) {
523
+ const hasWeakCapture = closureText.includes('weak') ||
524
+ closureText.includes('unowned');
525
+
526
+ if (!hasWeakCapture) {
527
+ const line = closure['key.line'] || 1;
528
+ this.pushFinding('ios.memory.missing_weak_self', 'high', filePath, line,
529
+ 'Escaping closure captures self without [weak self]');
530
+ }
531
+ }
532
+ }
533
+ }
534
+
535
+ analyzeCleanArchitectureAST(filePath) {
536
+ const fileName = path.basename(filePath);
537
+
538
+ if (fileName.includes('UseCase')) {
539
+ const hasVoidReturn = this.functions.some(f => {
540
+ const typename = f['key.typename'] || '';
541
+ return (f['key.name'] || '').includes('execute') && typename.includes('Void');
542
+ });
543
+
544
+ if (hasVoidReturn) {
545
+ this.pushFinding('ios.architecture.usecase_void', 'medium', filePath, 1,
546
+ 'UseCase returns Void - consider returning Result');
547
+ }
548
+
549
+ if (!filePath.includes('/Domain/') && !filePath.includes('/Application/')) {
550
+ this.pushFinding('ios.architecture.usecase_wrong_layer', 'high', filePath, 1,
551
+ 'UseCase should be in Domain or Application layer');
552
+ }
553
+ }
554
+
555
+ if (filePath.includes('/Infrastructure/')) {
556
+ const hasUIImport = this.imports.some(i => ['SwiftUI', 'UIKit'].includes(i.name));
557
+ if (hasUIImport) {
558
+ this.pushFinding('ios.architecture.infrastructure_ui', 'critical', filePath, 1,
559
+ 'Infrastructure layer imports UI framework - violates Clean Architecture');
560
+ }
561
+ }
562
+
563
+ if (filePath.includes('/Presentation/') || filePath.includes('/Views/')) {
564
+ const hasInfraImport = this.imports.some(i =>
565
+ i.name.includes('Alamofire') || i.name.includes('Realm') || i.name.includes('CoreData')
566
+ );
567
+ if (hasInfraImport) {
568
+ this.pushFinding('ios.architecture.presentation_infra', 'high', filePath, 1,
569
+ 'Presentation imports Infrastructure directly - use Domain layer');
570
+ }
571
+ }
572
+ }
573
+
574
+ analyzeAdditionalRules(filePath) {
575
+ if (filePath.includes('ViewModel') && this.fileContent.includes('NavigationLink')) {
576
+ const hasCoordinator = this.imports.some(i => i.name.includes('Coordinator'));
577
+ if (!hasCoordinator) {
578
+ this.pushFinding('ios.architecture.missing_coordinator', 'medium', filePath, 1,
579
+ 'Navigation in ViewModel - consider Coordinator pattern');
580
+ }
581
+ }
582
+
583
+ if (this.fileContent.includes('DispatchQueue.main') || this.fileContent.includes('DispatchQueue.global')) {
584
+ const line = this.findLineNumber('DispatchQueue');
585
+ this.pushFinding('ios.concurrency.dispatch_queue', 'medium', filePath, line,
586
+ 'DispatchQueue detected - use async/await in new code');
587
+ }
588
+
589
+ if (/Task\s*\{/.test(this.fileContent) && !/Task\s*\{[^}]*do\s*\{/.test(this.fileContent)) {
590
+ const line = this.findLineNumber('Task {');
591
+ this.pushFinding('ios.concurrency.task_no_error_handling', 'high', filePath, line,
592
+ 'Task without do-catch - handle errors');
593
+ }
594
+
595
+ if (this.fileContent.includes('UserDefaults') && /password|token|secret|key/i.test(this.fileContent)) {
596
+ const line = this.findLineNumber('UserDefaults');
597
+ this.pushFinding('ios.security.sensitive_userdefaults', 'critical', filePath, line,
598
+ 'Sensitive data in UserDefaults - use Keychain');
599
+ }
600
+
601
+ const hardcodedStrings = this.fileContent.match(/Text\s*\(\s*"[^"]{10,}"\s*\)/g) || [];
602
+ if (hardcodedStrings.length > 3) {
603
+ this.pushFinding('ios.i18n.hardcoded_strings', 'medium', filePath, 1,
604
+ `${hardcodedStrings.length} hardcoded strings - use NSLocalizedString`);
605
+ }
606
+
607
+ if (this.fileContent.includes('Image(') && !this.fileContent.includes('.accessibilityLabel')) {
608
+ const imageCount = (this.fileContent.match(/Image\s*\(/g) || []).length;
609
+ const labelCount = (this.fileContent.match(/\.accessibilityLabel/g) || []).length;
610
+ if (imageCount > labelCount + 2) {
611
+ this.pushFinding('ios.accessibility.missing_labels', 'medium', filePath, 1,
612
+ 'Images without accessibilityLabel - add for VoiceOver');
613
+ }
614
+ }
615
+
616
+ if (this.fileContent.includes('@IBOutlet') || this.fileContent.includes('@IBAction')) {
617
+ const line = this.findLineNumber('@IB');
618
+ this.pushFinding('ios.deprecated.storyboard', 'low', filePath, line,
619
+ 'Storyboard/XIB detected - consider SwiftUI or programmatic UI');
620
+ }
621
+
622
+ const completionCount = (this.fileContent.match(/completion\s*:\s*@escaping/g) || []).length;
623
+ if (completionCount > 2) {
624
+ this.pushFinding('ios.concurrency.completion_handlers', 'medium', filePath, 1,
625
+ `${completionCount} completion handlers - use async/await`);
626
+ }
627
+
628
+ for (const cls of this.classes) {
629
+ const hasSharedState = this.properties.some(p =>
630
+ (p['key.kind'] || '').includes('static') &&
631
+ !this.hasAttribute(p, 'MainActor') &&
632
+ !this.hasAttribute(p, 'nonisolated')
633
+ );
634
+ if (hasSharedState && !this.fileContent.includes('actor ')) {
635
+ const name = cls['key.name'] || '';
636
+ const line = cls['key.line'] || 1;
637
+ this.pushFinding('ios.concurrency.missing_actor', 'high', filePath, line,
638
+ `Class '${name}' has shared state - consider actor for thread safety`);
639
+ }
640
+ }
641
+
642
+ for (const cls of this.classes) {
643
+ const name = cls['key.name'] || '';
644
+ const inheritedTypes = (cls['key.inheritedtypes'] || []).map(t => t['key.name']);
645
+ const hasAsync = this.functions.some(f => this.hasAttribute(f, 'async'));
646
+
647
+ if (hasAsync && !inheritedTypes.includes('Sendable') && !name.includes('ViewModel')) {
648
+ const line = cls['key.line'] || 1;
649
+ this.pushFinding('ios.concurrency.missing_sendable', 'medium', filePath, line,
650
+ `Class '${name}' used in async context - consider Sendable conformance`);
651
+ }
652
+ }
653
+ }
654
+
655
+ findLineNumber(text) {
656
+ const idx = this.fileContent.indexOf(text);
657
+ if (idx === -1) return 1;
658
+ return this.fileContent.substring(0, idx).split('\n').length;
659
+ }
660
+
661
+ hasAttribute(node, attrName) {
662
+ const attributes = node['key.attributes'] || [];
663
+ return attributes.some(a => (a['key.attribute'] || '').includes(attrName));
664
+ }
665
+
666
+ getAttributes(node) {
667
+ const attributes = node['key.attributes'] || [];
668
+ return attributes.map(a => {
669
+ const attr = a['key.attribute'] || '';
670
+ return attr.replace('source.decl.attribute.', '');
671
+ });
672
+ }
673
+
674
+ findUnusedPropertiesAST(properties, methods) {
675
+ const unused = [];
676
+
677
+ for (const prop of properties) {
678
+ const propName = prop['key.name'];
679
+ if (!propName) continue;
680
+
681
+ if (this.hasAttribute(prop, 'Published') ||
682
+ this.hasAttribute(prop, 'State') ||
683
+ this.hasAttribute(prop, 'Binding')) {
684
+ continue;
685
+ }
686
+
687
+ let usageCount = 0;
688
+ for (const method of methods) {
689
+ const methodText = this.safeStringify(method);
690
+ if (methodText.includes(`"${propName}"`)) {
691
+ usageCount++;
692
+ }
693
+ }
694
+
695
+ if (usageCount === 0) {
696
+ unused.push(propName);
697
+ }
698
+ }
699
+
700
+ return unused;
701
+ }
702
+
703
+ calculateComplexityAST(substructure) {
704
+ let complexity = 1;
705
+
706
+ const traverse = (nodes) => {
707
+ if (!Array.isArray(nodes)) return;
708
+
709
+ for (const node of nodes) {
710
+ const kind = node['key.kind'] || '';
711
+
712
+ if (kind.includes('stmt.if') || kind.includes('stmt.guard') ||
713
+ kind.includes('stmt.switch') || kind.includes('stmt.for') ||
714
+ kind.includes('stmt.while') || kind.includes('stmt.catch')) {
715
+ complexity++;
716
+ }
717
+
718
+ traverse(node['key.substructure'] || []);
719
+ }
720
+ };
721
+
722
+ traverse(substructure);
723
+ return complexity;
724
+ }
725
+
726
+ countClosuresInNode(node) {
727
+ let count = 0;
728
+ const traverse = (n) => {
729
+ if ((n['key.kind'] || '').includes('closure')) count++;
730
+ for (const child of (n['key.substructure'] || [])) {
731
+ traverse(child);
732
+ }
733
+ };
734
+ traverse(node);
735
+ return count;
736
+ }
737
+
738
+ countStatementsOfType(substructure, stmtType) {
739
+ let count = 0;
740
+ const traverse = (nodes) => {
741
+ if (!Array.isArray(nodes)) return;
742
+ for (const node of nodes) {
743
+ if ((node['key.kind'] || '').includes(stmtType)) count++;
744
+ traverse(node['key.substructure'] || []);
745
+ }
746
+ };
747
+ traverse(substructure);
748
+ return count;
749
+ }
750
+
751
+ checkDependencyInjectionAST(properties, filePath, className, line) {
752
+ if (!className.includes('ViewModel') && !className.includes('Service') &&
753
+ !className.includes('Repository') && !className.includes('UseCase')) {
754
+ return;
755
+ }
756
+
757
+ for (const prop of properties) {
758
+ const typename = prop['key.typename'] || '';
759
+
760
+ if (['String', 'Int', 'Bool', 'Double', 'Float', 'Date', 'URL', 'Data'].includes(typename)) {
761
+ continue;
762
+ }
763
+
764
+ const isConcreteService = /Service$|Repository$|UseCase$|Client$/.test(typename) &&
765
+ !typename.includes('Protocol') &&
766
+ !typename.includes('any ') &&
767
+ !typename.includes('some ');
768
+
769
+ if (isConcreteService) {
770
+ this.pushFinding('ios.solid.dip.concrete_dependency', 'high', filePath, line,
771
+ `'${className}' depends on concrete '${typename}' - use protocol`);
772
+ }
773
+ }
774
+ }
775
+
776
+ pushFinding(ruleId, severity, filePath, line, message) {
777
+ this.findings.push({
778
+ ruleId,
779
+ severity: severity.toUpperCase(),
780
+ filePath,
781
+ line,
782
+ column: 1,
783
+ message,
784
+ });
785
+ }
786
+
787
+ finalizeGodClassDetection() {
788
+ if (!this.godClassCandidates || this.godClassCandidates.length < 10) return;
789
+
790
+ const quantile = (values, p) => {
791
+ if (!values || values.length === 0) return 0;
792
+ const sorted = [...values].filter((v) => Number.isFinite(v)).sort((a, b) => a - b);
793
+ if (sorted.length === 0) return 0;
794
+ const idx = Math.max(0, Math.min(sorted.length - 1, Math.ceil((p / 100) * sorted.length) - 1));
795
+ return sorted[idx];
796
+ };
797
+
798
+ const median = (values) => {
799
+ if (!values || values.length === 0) return 0;
800
+ const sorted = [...values].filter((v) => Number.isFinite(v)).sort((a, b) => a - b);
801
+ if (sorted.length === 0) return 0;
802
+ const mid = Math.floor(sorted.length / 2);
803
+ if (sorted.length % 2 === 0) return (sorted[mid - 1] + sorted[mid]) / 2;
804
+ return sorted[mid];
805
+ };
806
+
807
+ const mad = (values) => {
808
+ const med = median(values);
809
+ const deviations = (values || []).map((v) => Math.abs(v - med));
810
+ return median(deviations);
811
+ };
812
+
813
+ const robustZ = (x, med, madValue) => {
814
+ if (!Number.isFinite(x) || !Number.isFinite(med) || !Number.isFinite(madValue) || madValue === 0) return 0;
815
+ return 0.6745 * (x - med) / madValue;
816
+ };
817
+
818
+ const pOutlier = Number(process.env.AST_GODCLASS_P_OUTLIER || 90);
819
+ const pExtreme = Number(process.env.AST_GODCLASS_P_EXTREME || 97);
820
+
821
+ const methods = this.godClassCandidates.map(c => c.methodsCount);
822
+ const props = this.godClassCandidates.map(c => c.propertiesCount);
823
+ const bodies = this.godClassCandidates.map(c => c.bodyLength);
824
+ const complexities = this.godClassCandidates.map(c => c.complexity);
825
+
826
+ const med = {
827
+ methodsCount: median(methods),
828
+ propertiesCount: median(props),
829
+ bodyLength: median(bodies),
830
+ complexity: median(complexities),
831
+ };
832
+ const madValue = {
833
+ methodsCount: mad(methods),
834
+ propertiesCount: mad(props),
835
+ bodyLength: mad(bodies),
836
+ complexity: mad(complexities),
837
+ };
838
+
839
+ const z = {
840
+ methodsCount: methods.map(v => robustZ(v, med.methodsCount, madValue.methodsCount)),
841
+ propertiesCount: props.map(v => robustZ(v, med.propertiesCount, madValue.propertiesCount)),
842
+ bodyLength: bodies.map(v => robustZ(v, med.bodyLength, madValue.bodyLength)),
843
+ complexity: complexities.map(v => robustZ(v, med.complexity, madValue.complexity)),
844
+ };
845
+
846
+ const thresholds = {
847
+ outlier: {
848
+ methodsCountZ: quantile(z.methodsCount, pOutlier),
849
+ propertiesCountZ: quantile(z.propertiesCount, pOutlier),
850
+ bodyLengthZ: quantile(z.bodyLength, pOutlier),
851
+ complexityZ: quantile(z.complexity, pOutlier),
852
+ },
853
+ extreme: {
854
+ methodsCountZ: quantile(z.methodsCount, pExtreme),
855
+ propertiesCountZ: quantile(z.propertiesCount, pExtreme),
856
+ bodyLengthZ: quantile(z.bodyLength, pExtreme),
857
+ complexityZ: quantile(z.complexity, pExtreme),
858
+ }
859
+ };
860
+
861
+ for (const c of this.godClassCandidates) {
862
+ const methodsZ = robustZ(c.methodsCount, med.methodsCount, madValue.methodsCount);
863
+ const propsZ = robustZ(c.propertiesCount, med.propertiesCount, madValue.propertiesCount);
864
+ const bodyZ = robustZ(c.bodyLength, med.bodyLength, madValue.bodyLength);
865
+ const complexityZ = robustZ(c.complexity, med.complexity, madValue.complexity);
866
+
867
+ const sizeOutlier =
868
+ (methodsZ > 0 && methodsZ >= thresholds.outlier.methodsCountZ) ||
869
+ (propsZ > 0 && propsZ >= thresholds.outlier.propertiesCountZ) ||
870
+ (bodyZ > 0 && bodyZ >= thresholds.outlier.bodyLengthZ);
871
+ const complexityOutlier = complexityZ > 0 && complexityZ >= thresholds.outlier.complexityZ;
872
+
873
+ const extremeOutlier =
874
+ (methodsZ > 0 && methodsZ >= thresholds.extreme.methodsCountZ) ||
875
+ (propsZ > 0 && propsZ >= thresholds.extreme.propertiesCountZ) ||
876
+ (bodyZ > 0 && bodyZ >= thresholds.extreme.bodyLengthZ) ||
877
+ (complexityZ > 0 && complexityZ >= thresholds.extreme.complexityZ);
878
+
879
+ const signalCount = [sizeOutlier, complexityOutlier].filter(Boolean).length;
880
+
881
+ if (extremeOutlier || signalCount >= 2) {
882
+ this.pushFinding(
883
+ 'ios.solid.srp.god_class',
884
+ 'critical',
885
+ c.filePath,
886
+ c.line,
887
+ `God class '${c.name}': ${c.methodsCount} methods (z=${methodsZ.toFixed(2)}), ${c.propertiesCount} properties (z=${propsZ.toFixed(2)}), body ${c.bodyLength} (z=${bodyZ.toFixed(2)}), complexity ${c.complexity} (z=${complexityZ.toFixed(2)}) - VIOLATES SRP`
888
+ );
889
+ }
890
+ }
891
+ }
892
+ }
893
+
894
+ module.exports = { iOSASTIntelligentAnalyzer };