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.
- package/LICENSE +21 -0
- package/README.md +1105 -0
- package/bin/__tests__/auto-fix-violations.spec.js +132 -0
- package/bin/__tests__/auto-restart-guards.spec.js +11 -0
- package/bin/__tests__/check-doc-drift.spec.js +11 -0
- package/bin/__tests__/check-version.spec.js +240 -0
- package/bin/__tests__/cli.spec.js +11 -0
- package/bin/__tests__/guard-auto-manager.spec.js +11 -0
- package/bin/__tests__/guard-supervisor.spec.js +11 -0
- package/bin/__tests__/hook-status.spec.js +11 -0
- package/bin/__tests__/install.spec.js +11 -0
- package/bin/__tests__/nightly-metrics-report.spec.js +94 -0
- package/bin/__tests__/plan-review.spec.js +11 -0
- package/bin/__tests__/predictive-hooks.spec.js +11 -0
- package/bin/__tests__/run-ast-adapter.spec.js +11 -0
- package/bin/__tests__/run-orchestrator.spec.js +11 -0
- package/bin/__tests__/run-playbook.spec.js +11 -0
- package/bin/__tests__/setup-eslint.spec.js +11 -0
- package/bin/__tests__/violations-api.spec.js +11 -0
- package/bin/__tests__/watch-hooks.spec.js +11 -0
- package/bin/ai-commit.sh +5 -0
- package/bin/audit +5 -0
- package/bin/audit-library.js +6 -0
- package/bin/auto-fix-violations.js +19 -0
- package/bin/auto-restart-guards.js +6 -0
- package/bin/check-doc-drift.js +6 -0
- package/bin/check-version.js +19 -0
- package/bin/cleanup-branches.sh +5 -0
- package/bin/cli.js +6 -0
- package/bin/demo-recording.sh +5 -0
- package/bin/demo-violations +5 -0
- package/bin/fix-enforcer +5 -0
- package/bin/fix-gitflow-enforcement.sh +5 -0
- package/bin/generate-progress-report.sh +5 -0
- package/bin/git-analyze-pairs.sh +5 -0
- package/bin/git-leave-branch-check.sh +5 -0
- package/bin/gitflow +5 -0
- package/bin/gitflow-shell-integration.sh +5 -0
- package/bin/guard-auto-manager.js +6 -0
- package/bin/guard-autostart.sh +5 -0
- package/bin/guard-env.sh +5 -0
- package/bin/guard-supervisor.js +6 -0
- package/bin/hook-status.js +6 -0
- package/bin/install-git-wrapper.sh +5 -0
- package/bin/install.js +6 -0
- package/bin/kill-mcp-zombies.sh +5 -0
- package/bin/nightly-metrics-report.js +8 -0
- package/bin/plan-review.js +6 -0
- package/bin/predictive-hooks.js +6 -0
- package/bin/pumuki-audit.js +6 -0
- package/bin/pumuki-init.js +19 -0
- package/bin/pumuki-mcp-server.js +13 -0
- package/bin/pumuki-mcp.js +6 -0
- package/bin/pumuki-rules.js +6 -0
- package/bin/request-no-verify-approval.sh +5 -0
- package/bin/run-ast-adapter.js +6 -0
- package/bin/run-intelligent-audit.sh +5 -0
- package/bin/run-orchestrator.js +6 -0
- package/bin/run-playbook.js +6 -0
- package/bin/session-loader.sh +5 -0
- package/bin/setup-eslint.js +6 -0
- package/bin/start-guards.sh +5 -0
- package/bin/sync-autonomous-orchestrator.sh +5 -0
- package/bin/sync-to-library.sh +5 -0
- package/bin/update-evidence.sh +5 -0
- package/bin/update-session-context.sh +5 -0
- package/bin/verify-no-verify.sh +5 -0
- package/bin/violations +5 -0
- package/bin/violations-api.js +6 -0
- package/bin/watch-hooks.js +6 -0
- package/docs/API_REFERENCE.md +161 -0
- package/docs/ARCHITECTURE.md +236 -0
- package/docs/ARCHITECTURE_DETAILED.md +499 -0
- package/docs/BRANCH_PROTECTION_GUIDE.md +236 -0
- package/docs/CODE_STANDARDS.md +440 -0
- package/docs/CONTRIBUTING.md +246 -0
- package/docs/DEPENDENCIES.md +541 -0
- package/docs/HOW_IT_WORKS.md +716 -0
- package/docs/INSTALLATION.md +784 -0
- package/docs/MCP_SERVERS.md +786 -0
- package/docs/TESTING.md +423 -0
- package/docs/USAGE.md +856 -0
- package/docs/images/ast_intelligence_01.png +0 -0
- package/docs/images/ast_intelligence_02.png +0 -0
- package/docs/images/ast_intelligence_03.png +0 -0
- package/docs/images/ast_intelligence_04.png +0 -0
- package/docs/images/ast_intelligence_05.png +0 -0
- package/hooks/getSkillRulesPath.ts +52 -0
- package/hooks/git-status-monitor.ts +160 -0
- package/hooks/index.js +5 -0
- package/hooks/notify-macos.ts +42 -0
- package/hooks/package.json +16 -0
- package/hooks/post-tool-use-tracker.sh +89 -0
- package/hooks/pre-tool-use-evidence-validator.ts +252 -0
- package/hooks/pre-tool-use-guard.ts +151 -0
- package/hooks/skill-activation-prompt.sh +8 -0
- package/hooks/skill-activation-prompt.ts +307 -0
- package/index.js +49 -0
- package/package.json +117 -0
- package/presentation/cli/audit.sh +24 -0
- package/presentation/cli/autonomous-status.sh +92 -0
- package/presentation/cli/categorize-violations.sh +179 -0
- package/presentation/cli/direct-audit-option2.sh +23 -0
- package/presentation/cli/direct-audit.sh +33 -0
- package/scripts/hooks-system/.AI_TOKEN_STATUS.txt +16 -0
- package/scripts/hooks-system/.audit-reports/auto-recovery.log +1 -0
- package/scripts/hooks-system/.audit-reports/install-wizard.log +4 -0
- package/scripts/hooks-system/.audit-reports/notifications.log +425 -0
- package/scripts/hooks-system/.audit-reports/token-monitor.log +1275 -0
- package/scripts/hooks-system/.audit_tmp/intelligent-report.json +44953 -0
- package/scripts/hooks-system/.audit_tmp/intelligent-report.txt +1338 -0
- package/scripts/hooks-system/.audit_tmp/severity-history.jsonl +1 -0
- package/scripts/hooks-system/.audit_tmp/token-usage.jsonl +1 -0
- package/scripts/hooks-system/.hook-system/config.json +8 -0
- package/scripts/hooks-system/application/CompositionRoot.js +325 -0
- package/scripts/hooks-system/application/__tests__/CompositionRoot.spec.js +84 -0
- package/scripts/hooks-system/application/commands/index.js +64 -0
- package/scripts/hooks-system/application/queries/index.js +60 -0
- package/scripts/hooks-system/application/services/AutonomousOrchestrator.js +130 -0
- package/scripts/hooks-system/application/services/ContextDetectionEngine.js +181 -0
- package/scripts/hooks-system/application/services/DynamicRulesLoader.js +182 -0
- package/scripts/hooks-system/application/services/GitFlowService.js +156 -0
- package/scripts/hooks-system/application/services/GitTreeState.js +140 -0
- package/scripts/hooks-system/application/services/HookSystemScheduler.js +77 -0
- package/scripts/hooks-system/application/services/IntelligentCommitAnalyzer.js +151 -0
- package/scripts/hooks-system/application/services/IntelligentGitTreeMonitor.js +118 -0
- package/scripts/hooks-system/application/services/PlatformAnalysisService.js +173 -0
- package/scripts/hooks-system/application/services/PlatformDetectionService.js +168 -0
- package/scripts/hooks-system/application/services/PlaybookRunner.js +39 -0
- package/scripts/hooks-system/application/services/PredictiveHookAdvisor.js +56 -0
- package/scripts/hooks-system/application/services/RealtimeGuardPlugin.js +62 -0
- package/scripts/hooks-system/application/services/RealtimeGuardService.js +374 -0
- package/scripts/hooks-system/application/services/SmartDirtyTreeAnalyzer.js +63 -0
- package/scripts/hooks-system/application/services/__tests__/AutonomousOrchestrator.spec.js +36 -0
- package/scripts/hooks-system/application/services/__tests__/ContextDetectionEngine.spec.js +33 -0
- package/scripts/hooks-system/application/services/__tests__/DynamicRulesLoader.spec.js +43 -0
- package/scripts/hooks-system/application/services/__tests__/GitTreeState.spec.js +163 -0
- package/scripts/hooks-system/application/services/__tests__/HookSystemScheduler.spec.js +207 -0
- package/scripts/hooks-system/application/services/__tests__/IntelligentCommitAnalyzer.spec.js +365 -0
- package/scripts/hooks-system/application/services/__tests__/IntelligentGitTreeMonitor.spec.js +188 -0
- package/scripts/hooks-system/application/services/__tests__/PlatformDetectionService.spec.js +28 -0
- package/scripts/hooks-system/application/services/__tests__/PlaybookRunner.spec.js +143 -0
- package/scripts/hooks-system/application/services/__tests__/PredictiveHookAdvisor.spec.js +181 -0
- package/scripts/hooks-system/application/services/__tests__/RealtimeGuardPlugin.spec.js +45 -0
- package/scripts/hooks-system/application/services/__tests__/RealtimeGuardService.critical.spec.js +401 -0
- package/scripts/hooks-system/application/services/commit/CommitMessageGenerator.js +34 -0
- package/scripts/hooks-system/application/services/commit/FeatureDetector.js +101 -0
- package/scripts/hooks-system/application/services/evidence/EvidenceContextManager.js +163 -0
- package/scripts/hooks-system/application/services/evidence/__tests__/EvidenceContextManager.spec.js +98 -0
- package/scripts/hooks-system/application/services/guard/GuardAutoManagerService.js +169 -0
- package/scripts/hooks-system/application/services/guard/GuardConfig.js +15 -0
- package/scripts/hooks-system/application/services/guard/GuardEventLogger.js +70 -0
- package/scripts/hooks-system/application/services/guard/GuardHealthReminder.js +54 -0
- package/scripts/hooks-system/application/services/guard/GuardHeartbeatMonitor.js +94 -0
- package/scripts/hooks-system/application/services/guard/GuardLockManager.js +72 -0
- package/scripts/hooks-system/application/services/guard/GuardMonitorLoop.js +29 -0
- package/scripts/hooks-system/application/services/guard/GuardNotificationHandler.js +36 -0
- package/scripts/hooks-system/application/services/guard/GuardProcessManager.js +113 -0
- package/scripts/hooks-system/application/services/guard/GuardRecoveryService.js +90 -0
- package/scripts/hooks-system/application/services/guard/__tests__/GuardAutoManagerService.spec.js +77 -0
- package/scripts/hooks-system/application/services/installation/ConfigurationGeneratorService.js +123 -0
- package/scripts/hooks-system/application/services/installation/FileSystemInstallerService.js +112 -0
- package/scripts/hooks-system/application/services/installation/GitEnvironmentService.js +166 -0
- package/scripts/hooks-system/application/services/installation/HookInstaller.js +197 -0
- package/scripts/hooks-system/application/services/installation/IdeIntegrationService.js +37 -0
- package/scripts/hooks-system/application/services/installation/InstallService.js +130 -0
- package/scripts/hooks-system/application/services/installation/McpConfigurator.js +172 -0
- package/scripts/hooks-system/application/services/installation/PlatformDetectorService.js +36 -0
- package/scripts/hooks-system/application/services/installation/VSCodeTaskConfigurator.js +97 -0
- package/scripts/hooks-system/application/services/logging/UnifiedLogger.js +142 -0
- package/scripts/hooks-system/application/services/logging/__tests__/UnifiedLogger.spec.js +66 -0
- package/scripts/hooks-system/application/services/monitoring/ActivityMonitor.js +80 -0
- package/scripts/hooks-system/application/services/monitoring/AstMonitor.js +140 -0
- package/scripts/hooks-system/application/services/monitoring/DevDocsMonitor.js +85 -0
- package/scripts/hooks-system/application/services/monitoring/EvidenceMonitor.js +103 -0
- package/scripts/hooks-system/application/services/monitoring/EvidenceMonitorService.js +162 -0
- package/scripts/hooks-system/application/services/monitoring/GitTreeMonitor.js +123 -0
- package/scripts/hooks-system/application/services/monitoring/GitTreeMonitorService.js +114 -0
- package/scripts/hooks-system/application/services/monitoring/HealthCheckProviders.js +153 -0
- package/scripts/hooks-system/application/services/monitoring/HealthCheckService.js +118 -0
- package/scripts/hooks-system/application/services/monitoring/HeartbeatMonitorService.js +61 -0
- package/scripts/hooks-system/application/services/monitoring/TokenMonitor.js +60 -0
- package/scripts/hooks-system/application/services/monitoring/__tests__/EvidenceMonitorService.spec.js +107 -0
- package/scripts/hooks-system/application/services/monitoring/__tests__/GitTreeMonitorService.spec.js +27 -0
- package/scripts/hooks-system/application/services/monitoring/__tests__/HealthCheckProviders.spec.js +68 -0
- package/scripts/hooks-system/application/services/monitoring/__tests__/HealthCheckService.spec.js +69 -0
- package/scripts/hooks-system/application/services/monitoring/__tests__/HeartbeatMonitorService.spec.js +35 -0
- package/scripts/hooks-system/application/services/notification/MacNotificationSender.js +106 -0
- package/scripts/hooks-system/application/services/notification/NotificationCenterService.js +221 -0
- package/scripts/hooks-system/application/services/notification/NotificationDispatcher.js +42 -0
- package/scripts/hooks-system/application/services/notification/__tests__/NotificationCenterService.spec.js +40 -0
- package/scripts/hooks-system/application/services/notification/components/NotificationCooldownManager.js +62 -0
- package/scripts/hooks-system/application/services/notification/components/NotificationDeduplicator.js +67 -0
- package/scripts/hooks-system/application/services/notification/components/NotificationQueue.js +36 -0
- package/scripts/hooks-system/application/services/notification/components/NotificationRetryExecutor.js +58 -0
- package/scripts/hooks-system/application/services/platform/PlatformHeuristics.js +144 -0
- package/scripts/hooks-system/application/services/recovery/AutoRecoveryManager.js +137 -0
- package/scripts/hooks-system/application/services/recovery/__tests__/AutoRecoveryManager.spec.js +62 -0
- package/scripts/hooks-system/application/services/smart-commit/CommitMessageSuggester.js +97 -0
- package/scripts/hooks-system/application/services/smart-commit/FileContextGrouper.js +114 -0
- package/scripts/hooks-system/application/services/smart-commit/SmartCommitSummaryBuilder.js +53 -0
- package/scripts/hooks-system/application/services/token/CursorTokenService.js +44 -0
- package/scripts/hooks-system/application/services/token/TokenMetricsService.js +109 -0
- package/scripts/hooks-system/application/services/token/TokenMonitorService.js +160 -0
- package/scripts/hooks-system/application/services/token/TokenStatusReporter.js +56 -0
- package/scripts/hooks-system/application/services/token/__tests__/CursorTokenService.spec.js +69 -0
- package/scripts/hooks-system/application/services/token/__tests__/TokenMonitorService.spec.js +185 -0
- package/scripts/hooks-system/application/state/HookSystemStateMachine.js +59 -0
- package/scripts/hooks-system/application/state/__tests__/HookSystemStateMachine.spec.js +115 -0
- package/scripts/hooks-system/application/use-cases/AnalyzeCodebaseUseCase.js +54 -0
- package/scripts/hooks-system/application/use-cases/AnalyzeStagedFilesUseCase.js +61 -0
- package/scripts/hooks-system/application/use-cases/AutoExecuteAIStartUseCase.js +123 -0
- package/scripts/hooks-system/application/use-cases/BlockCommitUseCase.js +90 -0
- package/scripts/hooks-system/application/use-cases/GenerateAuditReportUseCase.js +184 -0
- package/scripts/hooks-system/application/use-cases/__tests__/AnalyzeCodebaseUseCase.spec.js +156 -0
- package/scripts/hooks-system/application/use-cases/__tests__/AnalyzeStagedFilesUseCase.spec.js +146 -0
- package/scripts/hooks-system/application/use-cases/__tests__/AutoExecuteAIStartUseCase.spec.js +89 -0
- package/scripts/hooks-system/application/use-cases/__tests__/BlockCommitUseCase.spec.js +171 -0
- package/scripts/hooks-system/application/use-cases/__tests__/GenerateAuditReportUseCase.spec.js +207 -0
- package/scripts/hooks-system/bin/__tests__/auto-fix-violations.spec.js +132 -0
- package/scripts/hooks-system/bin/__tests__/auto-restart-guards.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/check-doc-drift.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/check-version.spec.js +240 -0
- package/scripts/hooks-system/bin/__tests__/cli.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/guard-auto-manager.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/guard-supervisor.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/hook-status.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/install.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/nightly-metrics-report.spec.js +94 -0
- package/scripts/hooks-system/bin/__tests__/plan-review.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/predictive-hooks.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/run-ast-adapter.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/run-orchestrator.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/run-playbook.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/setup-eslint.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/violations-api.spec.js +11 -0
- package/scripts/hooks-system/bin/__tests__/watch-hooks.spec.js +11 -0
- package/scripts/hooks-system/bin/ai-commit.sh +63 -0
- package/scripts/hooks-system/bin/audit +463 -0
- package/scripts/hooks-system/bin/audit-library.js +54 -0
- package/scripts/hooks-system/bin/auto-fix-violations.js +130 -0
- package/scripts/hooks-system/bin/auto-restart-guards.js +93 -0
- package/scripts/hooks-system/bin/check-doc-drift.js +35 -0
- package/scripts/hooks-system/bin/check-version.js +201 -0
- package/scripts/hooks-system/bin/cleanup-branches.sh +106 -0
- package/scripts/hooks-system/bin/cli.js +208 -0
- package/scripts/hooks-system/bin/demo-recording.sh +57 -0
- package/scripts/hooks-system/bin/demo-violations +44 -0
- package/scripts/hooks-system/bin/fix-enforcer +27 -0
- package/scripts/hooks-system/bin/fix-gitflow-enforcement.sh +68 -0
- package/scripts/hooks-system/bin/generate-progress-report.sh +129 -0
- package/scripts/hooks-system/bin/git-analyze-pairs.sh +0 -0
- package/scripts/hooks-system/bin/git-leave-branch-check.sh +73 -0
- package/scripts/hooks-system/bin/gitflow +17 -0
- package/scripts/hooks-system/bin/gitflow-shell-integration.sh +64 -0
- package/scripts/hooks-system/bin/guard-auto-manager.js +44 -0
- package/scripts/hooks-system/bin/guard-autostart.sh +158 -0
- package/scripts/hooks-system/bin/guard-env.sh +40 -0
- package/scripts/hooks-system/bin/guard-supervisor.js +516 -0
- package/scripts/hooks-system/bin/hook-status.js +41 -0
- package/scripts/hooks-system/bin/install-git-wrapper.sh +53 -0
- package/scripts/hooks-system/bin/install.js +10 -0
- package/scripts/hooks-system/bin/kill-mcp-zombies.sh +48 -0
- package/scripts/hooks-system/bin/nightly-metrics-report.js +138 -0
- package/scripts/hooks-system/bin/plan-review.js +31 -0
- package/scripts/hooks-system/bin/predictive-hooks.js +18 -0
- package/scripts/hooks-system/bin/pumuki-audit.js +113 -0
- package/scripts/hooks-system/bin/pumuki-init.js +104 -0
- package/scripts/hooks-system/bin/pumuki-mcp.js +74 -0
- package/scripts/hooks-system/bin/pumuki-rules.js +74 -0
- package/scripts/hooks-system/bin/request-no-verify-approval.sh +116 -0
- package/scripts/hooks-system/bin/run-ast-adapter.js +86 -0
- package/scripts/hooks-system/bin/run-intelligent-audit.sh +67 -0
- package/scripts/hooks-system/bin/run-orchestrator.js +27 -0
- package/scripts/hooks-system/bin/run-playbook.js +23 -0
- package/scripts/hooks-system/bin/session-loader.sh +264 -0
- package/scripts/hooks-system/bin/setup-eslint.js +110 -0
- package/scripts/hooks-system/bin/start-guards.sh +190 -0
- package/scripts/hooks-system/bin/sync-autonomous-orchestrator.sh +32 -0
- package/scripts/hooks-system/bin/sync-to-library.sh +46 -0
- package/scripts/hooks-system/bin/update-evidence.sh +1167 -0
- package/scripts/hooks-system/bin/update-session-context.sh +261 -0
- package/scripts/hooks-system/bin/verify-no-verify.sh +68 -0
- package/scripts/hooks-system/bin/violations +20 -0
- package/scripts/hooks-system/bin/violations-api.js +345 -0
- package/scripts/hooks-system/bin/watch-hooks.js +20 -0
- package/scripts/hooks-system/config/project.config.json +36 -0
- package/scripts/hooks-system/config/state-map.json +12 -0
- package/scripts/hooks-system/domain/entities/AuditResult.js +139 -0
- package/scripts/hooks-system/domain/entities/Finding.js +116 -0
- package/scripts/hooks-system/domain/entities/SeverityConfig.js +73 -0
- package/scripts/hooks-system/domain/entities/SeverityConfig.ts +90 -0
- package/scripts/hooks-system/domain/entities/__tests__/AuditResult.spec.js +450 -0
- package/scripts/hooks-system/domain/entities/__tests__/Finding.spec.js +335 -0
- package/scripts/hooks-system/domain/entities/__tests__/SeverityConfig.spec.js +240 -0
- package/scripts/hooks-system/domain/entities/__tests__/entities.spec.js +29 -0
- package/scripts/hooks-system/domain/errors/__tests__/DomainErrors.spec.js +59 -0
- package/scripts/hooks-system/domain/errors/index.js +169 -0
- package/scripts/hooks-system/domain/events/__tests__/DomainEvents.spec.js +60 -0
- package/scripts/hooks-system/domain/events/index.js +121 -0
- package/scripts/hooks-system/domain/ports/IAstPort.js +67 -0
- package/scripts/hooks-system/domain/ports/IEvidencePort.js +86 -0
- package/scripts/hooks-system/domain/ports/IGitCommandPort.js +110 -0
- package/scripts/hooks-system/domain/ports/IGitPort.js +114 -0
- package/scripts/hooks-system/domain/ports/IGitQueryPort.js +93 -0
- package/scripts/hooks-system/domain/ports/INotificationPort.js +35 -0
- package/scripts/hooks-system/domain/ports/__tests__/ports.spec.js +36 -0
- package/scripts/hooks-system/domain/ports/index.js +14 -0
- package/scripts/hooks-system/domain/repositories/ICursorTokenRepository.js +13 -0
- package/scripts/hooks-system/domain/repositories/IFindingsRepository.js +30 -0
- package/scripts/hooks-system/domain/repositories/__tests__/IFindingsRepository.spec.js +18 -0
- package/scripts/hooks-system/domain/rules/CommitBlockingRules.js +142 -0
- package/scripts/hooks-system/domain/rules/__tests__/CommitBlockingRules.spec.js +18 -0
- package/scripts/hooks-system/domain/services/AuditAnalyzer.js +103 -0
- package/scripts/hooks-system/domain/services/AuditFilter.js +26 -0
- package/scripts/hooks-system/domain/services/AuditResultSerializer.js +35 -0
- package/scripts/hooks-system/domain/services/AuditScorer.js +38 -0
- package/scripts/hooks-system/domain/values/Severity.js +93 -0
- package/scripts/hooks-system/index.js +49 -0
- package/scripts/hooks-system/infrastructure/adapters/AstAnalyzerAdapter.js +150 -0
- package/scripts/hooks-system/infrastructure/adapters/FileEvidenceAdapter.js +140 -0
- package/scripts/hooks-system/infrastructure/adapters/GitCliAdapter.js +16 -0
- package/scripts/hooks-system/infrastructure/adapters/GitCommandAdapter.js +68 -0
- package/scripts/hooks-system/infrastructure/adapters/GitHubCliAdapter.js +85 -0
- package/scripts/hooks-system/infrastructure/adapters/GitQueryAdapter.js +58 -0
- package/scripts/hooks-system/infrastructure/adapters/LegacyAnalyzerAdapter.js +61 -0
- package/scripts/hooks-system/infrastructure/adapters/MacOSNotificationAdapter.js +99 -0
- package/scripts/hooks-system/infrastructure/adapters/__tests__/AstAnalyzerAdapter.spec.js +32 -0
- package/scripts/hooks-system/infrastructure/adapters/__tests__/FileEvidenceAdapter.spec.js +31 -0
- package/scripts/hooks-system/infrastructure/adapters/__tests__/GitCliAdapter.spec.js +39 -0
- package/scripts/hooks-system/infrastructure/adapters/__tests__/MacOSNotificationAdapter.spec.js +33 -0
- package/scripts/hooks-system/infrastructure/adapters/git/GitCommandRunner.js +78 -0
- package/scripts/hooks-system/infrastructure/adapters/git/GitCommandService.js +67 -0
- package/scripts/hooks-system/infrastructure/adapters/git/GitQueryService.js +50 -0
- package/scripts/hooks-system/infrastructure/adapters/index.js +14 -0
- package/scripts/hooks-system/infrastructure/ast/README.md +198 -0
- package/scripts/hooks-system/infrastructure/ast/__tests__/ast-core.spec.js +160 -0
- package/scripts/hooks-system/infrastructure/ast/__tests__/ast-intelligence.spec.js +20 -0
- package/scripts/hooks-system/infrastructure/ast/android/__tests__/ast-android.spec.js +33 -0
- package/scripts/hooks-system/infrastructure/ast/android/__tests__/clean-architecture-analyzer.spec.js +96 -0
- package/scripts/hooks-system/infrastructure/ast/android/__tests__/ddd-analyzer.spec.js +113 -0
- package/scripts/hooks-system/infrastructure/ast/android/__tests__/detekt-runner.spec.js +36 -0
- package/scripts/hooks-system/infrastructure/ast/android/__tests__/feature-first-analyzer.spec.js +80 -0
- package/scripts/hooks-system/infrastructure/ast/android/__tests__/native-bridge.spec.js +31 -0
- package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidASTIntelligentAnalyzer.js +15 -0
- package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidASTParser.js +157 -0
- package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidAnalysisOrchestrator.js +164 -0
- package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidArchitectureDetector.js +334 -0
- package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidClassAnalyzer.js +162 -0
- package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidForbiddenLiteralsAnalyzer.js +261 -0
- package/scripts/hooks-system/infrastructure/ast/android/analyzers/AndroidSOLIDAnalyzer.js +287 -0
- package/scripts/hooks-system/infrastructure/ast/android/analyzers/__tests__/AndroidForbiddenLiteralsAnalyzer.spec.js +58 -0
- package/scripts/hooks-system/infrastructure/ast/android/analyzers/__tests__/AndroidSOLIDAnalyzer.spec.js +84 -0
- package/scripts/hooks-system/infrastructure/ast/android/ast-android.js +1785 -0
- package/scripts/hooks-system/infrastructure/ast/android/clean-architecture-analyzer.js +115 -0
- package/scripts/hooks-system/infrastructure/ast/android/ddd-analyzer.js +70 -0
- package/scripts/hooks-system/infrastructure/ast/android/detekt-runner.js +81 -0
- package/scripts/hooks-system/infrastructure/ast/android/feature-first-analyzer.js +53 -0
- package/scripts/hooks-system/infrastructure/ast/android/native-bridge.js +119 -0
- package/scripts/hooks-system/infrastructure/ast/archive/README.md +18 -0
- package/scripts/hooks-system/infrastructure/ast/archive/ast-intelligence.ts +276 -0
- package/scripts/hooks-system/infrastructure/ast/archive/ios-rules.js +329 -0
- package/scripts/hooks-system/infrastructure/ast/archive/kotlin-analyzer.js +332 -0
- package/scripts/hooks-system/infrastructure/ast/archive/kotlin-parser.js +303 -0
- package/scripts/hooks-system/infrastructure/ast/archive/swift-analyzer.js +390 -0
- package/scripts/hooks-system/infrastructure/ast/ast-core.js +594 -0
- package/scripts/hooks-system/infrastructure/ast/ast-intelligence.js +617 -0
- package/scripts/hooks-system/infrastructure/ast/backend/__tests__/ast-backend.spec.js +20 -0
- package/scripts/hooks-system/infrastructure/ast/backend/__tests__/clean-architecture-analyzer.spec.js +151 -0
- package/scripts/hooks-system/infrastructure/ast/backend/__tests__/ddd-analyzer.spec.js +124 -0
- package/scripts/hooks-system/infrastructure/ast/backend/__tests__/feature-first-analyzer.spec.js +128 -0
- package/scripts/hooks-system/infrastructure/ast/backend/__tests__/forbidden-literals-analyzer.spec.js +95 -0
- package/scripts/hooks-system/infrastructure/ast/backend/__tests__/nestjs-patterns-analyzer.spec.js +59 -0
- package/scripts/hooks-system/infrastructure/ast/backend/__tests__/solid-analyzer.spec.js +114 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/BackendArchitectureDetector.js +141 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/BackendPatternDetector.js +23 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/__tests__/BackendArchitectureDetector.spec.js +239 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/__tests__/BackendPatternDetector.spec.js +58 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/CQRSDetector.js +41 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/CleanArchitectureDetector.js +52 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/FeatureFirstCleanDetector.js +74 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/LayeredArchitectureDetector.js +25 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/MVCDetector.js +32 -0
- package/scripts/hooks-system/infrastructure/ast/backend/analyzers/detectors/OnionArchitectureDetector.js +32 -0
- package/scripts/hooks-system/infrastructure/ast/backend/ast-backend-clean.js +44 -0
- package/scripts/hooks-system/infrastructure/ast/backend/ast-backend.js +2048 -0
- package/scripts/hooks-system/infrastructure/ast/backend/clean-architecture-analyzer.js +142 -0
- package/scripts/hooks-system/infrastructure/ast/backend/ddd-analyzer.js +256 -0
- package/scripts/hooks-system/infrastructure/ast/backend/feature-first-analyzer.js +70 -0
- package/scripts/hooks-system/infrastructure/ast/backend/forbidden-literals-analyzer.js +236 -0
- package/scripts/hooks-system/infrastructure/ast/backend/nestjs-patterns-analyzer.js +11 -0
- package/scripts/hooks-system/infrastructure/ast/backend/solid-analyzer.js +392 -0
- package/scripts/hooks-system/infrastructure/ast/common/BDDTDDWorkflowRules.js +52 -0
- package/scripts/hooks-system/infrastructure/ast/common/__tests__/BDDTDDWorkflowRules.spec.js +133 -0
- package/scripts/hooks-system/infrastructure/ast/common/__tests__/ast-common.spec.js +20 -0
- package/scripts/hooks-system/infrastructure/ast/common/__tests__/documentation-analyzer.spec.js +120 -0
- package/scripts/hooks-system/infrastructure/ast/common/__tests__/images-backend-analyzer.spec.js +123 -0
- package/scripts/hooks-system/infrastructure/ast/common/__tests__/monorepo-health-analyzer.spec.js +118 -0
- package/scripts/hooks-system/infrastructure/ast/common/__tests__/network-resilience-analyzer.spec.js +180 -0
- package/scripts/hooks-system/infrastructure/ast/common/__tests__/offline-backend-analyzer.spec.js +111 -0
- package/scripts/hooks-system/infrastructure/ast/common/__tests__/push-backend-analyzer.spec.js +124 -0
- package/scripts/hooks-system/infrastructure/ast/common/ast-common.js +345 -0
- package/scripts/hooks-system/infrastructure/ast/common/documentation-analyzer.js +217 -0
- package/scripts/hooks-system/infrastructure/ast/common/images-backend-analyzer.js +36 -0
- package/scripts/hooks-system/infrastructure/ast/common/monorepo-health-analyzer.js +452 -0
- package/scripts/hooks-system/infrastructure/ast/common/network-resilience-analyzer.js +178 -0
- package/scripts/hooks-system/infrastructure/ast/common/offline-backend-analyzer.js +53 -0
- package/scripts/hooks-system/infrastructure/ast/common/push-backend-analyzer.js +42 -0
- package/scripts/hooks-system/infrastructure/ast/common/rules/BDDRules.js +87 -0
- package/scripts/hooks-system/infrastructure/ast/common/rules/ImplementationRules.js +83 -0
- package/scripts/hooks-system/infrastructure/ast/common/rules/TDDRules.js +109 -0
- package/scripts/hooks-system/infrastructure/ast/common/rules/WorkflowRules.js +137 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/__tests__/ast-frontend.spec.js +20 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/FrontendArchitectureDetector.js +289 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/FrontendForbiddenLiteralsAnalyzer.js +257 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/FrontendSOLIDAnalyzer.js +274 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/__tests__/FrontendArchitectureDetector.spec.js +151 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/__tests__/FrontendForbiddenLiteralsAnalyzer.spec.js +20 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/analyzers/__tests__/FrontendSOLIDAnalyzer.spec.js +108 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/ast-frontend-clean.js +42 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/ast-frontend.js +2094 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/clean-architecture-analyzer.js +88 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/ddd-analyzer.js +94 -0
- package/scripts/hooks-system/infrastructure/ast/frontend/feature-first-analyzer.js +51 -0
- package/scripts/hooks-system/infrastructure/ast/ios/__tests__/ast-ios.spec.js +40 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSArchitectureDetector.spec.js +20 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSArchitectureRules.spec.js +61 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSCICDRules.spec.js +10 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSEnterpriseAnalyzer.spec.js +36 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSForbiddenLiteralsAnalyzer.spec.js +64 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSNetworkingAdvancedRules.spec.js +10 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSPerformanceRules.spec.js +34 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSSPMRules.spec.js +10 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/__tests__/iOSSwiftUIAdvancedRules.spec.js +10 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSASTIntelligentAnalyzer.js +894 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSArchitectureDetector.js +445 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSArchitectureRules.js +700 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSCICDRules.js +431 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSEnterpriseAnalyzer.js +580 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSForbiddenLiteralsAnalyzer.js +261 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSNetworkingAdvancedRules.js +177 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSPerformanceRules.js +11 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSSPMRules.js +496 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSSwiftUIAdvancedRules.js +333 -0
- package/scripts/hooks-system/infrastructure/ast/ios/analyzers/iOSTestingAdvancedRules.js +225 -0
- package/scripts/hooks-system/infrastructure/ast/ios/ast-ios.js +2176 -0
- package/scripts/hooks-system/infrastructure/ast/ios/native-bridge.js +92 -0
- package/scripts/hooks-system/infrastructure/ast/ios/parsers/SourceKittenParser.js +471 -0
- package/scripts/hooks-system/infrastructure/ast/ios/parsers/__tests__/SourceKittenParser.spec.js +41 -0
- package/scripts/hooks-system/infrastructure/ast/text/__tests__/text-scanner.spec.js +20 -0
- package/scripts/hooks-system/infrastructure/ast/text/text-scanner.js +1120 -0
- package/scripts/hooks-system/infrastructure/cache/CacheService.js +160 -0
- package/scripts/hooks-system/infrastructure/cli/__tests__/install-wizard.spec.js +16 -0
- package/scripts/hooks-system/infrastructure/cli/install-wizard.js +74 -0
- package/scripts/hooks-system/infrastructure/core/GitOperations.js +50 -0
- package/scripts/hooks-system/infrastructure/core/GitOperations.ts +112 -0
- package/scripts/hooks-system/infrastructure/core/__tests__/GitOperations.spec.js +146 -0
- package/scripts/hooks-system/infrastructure/eslint/eslint-integration.sh +75 -0
- package/scripts/hooks-system/infrastructure/events/EventListeners.js +143 -0
- package/scripts/hooks-system/infrastructure/events/__tests__/events.spec.js +14 -0
- package/scripts/hooks-system/infrastructure/external-tools/GitOperations.js +54 -0
- package/scripts/hooks-system/infrastructure/external-tools/eslint/backend.config.template.mjs +58 -0
- package/scripts/hooks-system/infrastructure/git-hooks/pre-push +35 -0
- package/scripts/hooks-system/infrastructure/git-server/pre-receive-hook +253 -0
- package/scripts/hooks-system/infrastructure/guards/git-wrapper.sh +32 -0
- package/scripts/hooks-system/infrastructure/guards/master-validator.sh +247 -0
- package/scripts/hooks-system/infrastructure/guards/prevent-no-verify.sh +34 -0
- package/scripts/hooks-system/infrastructure/hooks/__tests__/skill-activation-prompt.spec.js +11 -0
- package/scripts/hooks-system/infrastructure/hooks/pre-tool-use-intelligent-enforcer.sh +489 -0
- package/scripts/hooks-system/infrastructure/hooks/skill-activation-prompt.js +244 -0
- package/scripts/hooks-system/infrastructure/logging/UnifiedLoggerFactory.js +40 -0
- package/scripts/hooks-system/infrastructure/logging/__tests__/logging.spec.js +9 -0
- package/scripts/hooks-system/infrastructure/mcp/README.md +116 -0
- package/scripts/hooks-system/infrastructure/mcp/__tests__/ast-intelligence-automation.spec.js +38 -0
- package/scripts/hooks-system/infrastructure/mcp/__tests__/evidence-watcher.spec.js +38 -0
- package/scripts/hooks-system/infrastructure/mcp/ast-intelligence-automation.js +1097 -0
- package/scripts/hooks-system/infrastructure/mcp/evidence-watcher.js +128 -0
- package/scripts/hooks-system/infrastructure/mcp/package.json +17 -0
- package/scripts/hooks-system/infrastructure/mcp/services/EvidenceService.js +87 -0
- package/scripts/hooks-system/infrastructure/mcp/services/McpProtocolHandler.js +166 -0
- package/scripts/hooks-system/infrastructure/orchestration/__tests__/intelligent-audit.spec.js +11 -0
- package/scripts/hooks-system/infrastructure/orchestration/intelligent-audit.js +353 -0
- package/scripts/hooks-system/infrastructure/patterns/pattern-checks.sh +98 -0
- package/scripts/hooks-system/infrastructure/reporting/ReportImpactAnalyzer.js +109 -0
- package/scripts/hooks-system/infrastructure/reporting/ReportMetricsCalculator.js +114 -0
- package/scripts/hooks-system/infrastructure/reporting/ReportPresenter.js +86 -0
- package/scripts/hooks-system/infrastructure/reporting/__tests__/reporting.spec.js +15 -0
- package/scripts/hooks-system/infrastructure/reporting/report-generator.js +130 -0
- package/scripts/hooks-system/infrastructure/reporting/severity-tracker.js +105 -0
- package/scripts/hooks-system/infrastructure/repositories/CursorTokenRepository.js +76 -0
- package/scripts/hooks-system/infrastructure/repositories/FileFindingsRepository.js +88 -0
- package/scripts/hooks-system/infrastructure/repositories/__tests__/repositories.spec.js +20 -0
- package/scripts/hooks-system/infrastructure/repositories/datasources/CursorApiDataSource.js +73 -0
- package/scripts/hooks-system/infrastructure/repositories/datasources/CursorFileDataSource.js +55 -0
- package/scripts/hooks-system/infrastructure/severity/__tests__/severity-evaluator.spec.js +18 -0
- package/scripts/hooks-system/infrastructure/severity/analyzers/__tests__/maintainability-analyzer.spec.js +170 -0
- package/scripts/hooks-system/infrastructure/severity/analyzers/__tests__/performance-analyzer.spec.js +186 -0
- package/scripts/hooks-system/infrastructure/severity/analyzers/__tests__/security-analyzer.spec.js +151 -0
- package/scripts/hooks-system/infrastructure/severity/analyzers/__tests__/stability-analyzer.spec.js +143 -0
- package/scripts/hooks-system/infrastructure/severity/analyzers/maintainability-analyzer.js +100 -0
- package/scripts/hooks-system/infrastructure/severity/analyzers/performance-analyzer.js +109 -0
- package/scripts/hooks-system/infrastructure/severity/analyzers/security-analyzer.js +104 -0
- package/scripts/hooks-system/infrastructure/severity/analyzers/stability-analyzer.js +85 -0
- package/scripts/hooks-system/infrastructure/severity/context/analyzers/CodeClassificationAnalyzer.js +71 -0
- package/scripts/hooks-system/infrastructure/severity/context/analyzers/DataAnalyzer.js +64 -0
- package/scripts/hooks-system/infrastructure/severity/context/analyzers/ImpactAnalyzer.js +68 -0
- package/scripts/hooks-system/infrastructure/severity/context/analyzers/SafetyAnalyzer.js +82 -0
- package/scripts/hooks-system/infrastructure/severity/context/context-builder.js +88 -0
- package/scripts/hooks-system/infrastructure/severity/generators/RecommendationGenerator.js +153 -0
- package/scripts/hooks-system/infrastructure/severity/mappers/SeverityMapper.js +10 -0
- package/scripts/hooks-system/infrastructure/severity/policies/gate-policies.js +136 -0
- package/scripts/hooks-system/infrastructure/severity/policies/severity-policies.json +206 -0
- package/scripts/hooks-system/infrastructure/severity/scorers/ContextMultiplier.js +49 -0
- package/scripts/hooks-system/infrastructure/severity/severity-evaluator.js +117 -0
- package/scripts/hooks-system/infrastructure/shell/core/constants.sh +26 -0
- package/scripts/hooks-system/infrastructure/shell/core/utils.sh +45 -0
- package/scripts/hooks-system/infrastructure/shell/gitflow/git-wrapper.sh +646 -0
- package/scripts/hooks-system/infrastructure/shell/gitflow/gitflow-enforcer.sh +620 -0
- package/scripts/hooks-system/infrastructure/shell/gitflow/gitflow-state-manager.sh +235 -0
- package/scripts/hooks-system/infrastructure/shell/gitflow-state-manager.sh +225 -0
- package/scripts/hooks-system/infrastructure/shell/orchestrators/audit-orchestrator.sh +1106 -0
- package/scripts/hooks-system/infrastructure/shell/security/detect-secrets.sh +26 -0
- package/scripts/hooks-system/infrastructure/shell/security/detect_secrets.py +182 -0
- package/scripts/hooks-system/infrastructure/shell/validate-clean-architecture.sh +254 -0
- package/scripts/hooks-system/infrastructure/shell/validators/check-doc-structure.sh +62 -0
- package/scripts/hooks-system/infrastructure/shell/validators/ensure-critical-docs.sh +26 -0
- package/scripts/hooks-system/infrastructure/shell/validators/validate-ai-protocol.sh +474 -0
- package/scripts/hooks-system/infrastructure/shell/validators/validate-clean-architecture.sh +303 -0
- package/scripts/hooks-system/infrastructure/shell/validators/validate-conventional-commit.sh +42 -0
- package/scripts/hooks-system/infrastructure/storage/file-operations.sh +31 -0
- package/scripts/hooks-system/infrastructure/telemetry/TelemetryService.js +165 -0
- package/scripts/hooks-system/infrastructure/telemetry/__tests__/telemetry.spec.js +15 -0
- package/scripts/hooks-system/infrastructure/telemetry/metrics-logger.js +66 -0
- package/scripts/hooks-system/infrastructure/telemetry/metrics-server.js +61 -0
- package/scripts/hooks-system/infrastructure/utils/__tests__/utils.spec.js +8 -0
- package/scripts/hooks-system/infrastructure/utils/error-utils.js +28 -0
- package/scripts/hooks-system/infrastructure/utils/timestamp-helper.sh +106 -0
- package/scripts/hooks-system/infrastructure/utils/token-manager.js +121 -0
- package/scripts/hooks-system/infrastructure/validators/__tests__/detect-commit-language.spec.js +16 -0
- package/scripts/hooks-system/infrastructure/validators/__tests__/enforce-english-literals.spec.js +67 -0
- package/scripts/hooks-system/infrastructure/validators/detect-commit-language.js +145 -0
- package/scripts/hooks-system/infrastructure/validators/enforce-english-literals.js +202 -0
- package/scripts/hooks-system/infrastructure/watchdog/__tests__/.audit-reports/token-monitor.log +18 -0
- package/scripts/hooks-system/infrastructure/watchdog/__tests__/auto-recovery.spec.js +14 -0
- package/scripts/hooks-system/infrastructure/watchdog/__tests__/token-monitor.spec.js +67 -0
- package/scripts/hooks-system/infrastructure/watchdog/__tests__/watchdog.spec.js +22 -0
- package/scripts/hooks-system/infrastructure/watchdog/ai-watchdog.sh +278 -0
- package/scripts/hooks-system/infrastructure/watchdog/auto-recovery.js +32 -0
- package/scripts/hooks-system/infrastructure/watchdog/health-check.js +58 -0
- package/scripts/hooks-system/infrastructure/watchdog/token-monitor-loop.sh +20 -0
- package/scripts/hooks-system/infrastructure/watchdog/token-monitor.js +69 -0
- package/scripts/hooks-system/infrastructure/watchdog/token-tracker.sh +208 -0
- package/scripts/hooks-system/presentation/cli/audit.sh +32 -0
- package/scripts/hooks-system/presentation/cli/autonomous-status.sh +92 -0
- package/scripts/hooks-system/presentation/cli/categorize-violations.sh +179 -0
- package/scripts/hooks-system/presentation/cli/direct-audit-option2.sh +23 -0
- package/scripts/hooks-system/presentation/cli/direct-audit.sh +33 -0
- package/skills/android-guidelines/SKILL.md +475 -0
- package/skills/android-guidelines/resources/advanced-topics.md +44 -0
- package/skills/android-guidelines/resources/architecture-overview.md +44 -0
- package/skills/backend-guidelines/SKILL.md +335 -0
- package/skills/backend-guidelines/resources/architecture-overview.md +48 -0
- package/skills/frontend-guidelines/SKILL.md +367 -0
- package/skills/frontend-guidelines/resources/architecture-overview.md +44 -0
- package/skills/ios-guidelines/SKILL.md +406 -0
- package/skills/ios-guidelines/resources/architecture-overview.md +47 -0
- 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 };
|