attune-ai 2.0.0__py3-none-any.whl
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.
- attune/__init__.py +358 -0
- attune/adaptive/__init__.py +13 -0
- attune/adaptive/task_complexity.py +127 -0
- attune/agent_monitoring.py +414 -0
- attune/cache/__init__.py +117 -0
- attune/cache/base.py +166 -0
- attune/cache/dependency_manager.py +256 -0
- attune/cache/hash_only.py +251 -0
- attune/cache/hybrid.py +457 -0
- attune/cache/storage.py +285 -0
- attune/cache_monitor.py +356 -0
- attune/cache_stats.py +298 -0
- attune/cli/__init__.py +152 -0
- attune/cli/__main__.py +12 -0
- attune/cli/commands/__init__.py +1 -0
- attune/cli/commands/batch.py +264 -0
- attune/cli/commands/cache.py +248 -0
- attune/cli/commands/help.py +331 -0
- attune/cli/commands/info.py +140 -0
- attune/cli/commands/inspect.py +436 -0
- attune/cli/commands/inspection.py +57 -0
- attune/cli/commands/memory.py +48 -0
- attune/cli/commands/metrics.py +92 -0
- attune/cli/commands/orchestrate.py +184 -0
- attune/cli/commands/patterns.py +207 -0
- attune/cli/commands/profiling.py +202 -0
- attune/cli/commands/provider.py +98 -0
- attune/cli/commands/routing.py +285 -0
- attune/cli/commands/setup.py +96 -0
- attune/cli/commands/status.py +235 -0
- attune/cli/commands/sync.py +166 -0
- attune/cli/commands/tier.py +121 -0
- attune/cli/commands/utilities.py +114 -0
- attune/cli/commands/workflow.py +579 -0
- attune/cli/core.py +32 -0
- attune/cli/parsers/__init__.py +68 -0
- attune/cli/parsers/batch.py +118 -0
- attune/cli/parsers/cache.py +65 -0
- attune/cli/parsers/help.py +41 -0
- attune/cli/parsers/info.py +26 -0
- attune/cli/parsers/inspect.py +66 -0
- attune/cli/parsers/metrics.py +42 -0
- attune/cli/parsers/orchestrate.py +61 -0
- attune/cli/parsers/patterns.py +54 -0
- attune/cli/parsers/provider.py +40 -0
- attune/cli/parsers/routing.py +110 -0
- attune/cli/parsers/setup.py +42 -0
- attune/cli/parsers/status.py +47 -0
- attune/cli/parsers/sync.py +31 -0
- attune/cli/parsers/tier.py +33 -0
- attune/cli/parsers/workflow.py +77 -0
- attune/cli/utils/__init__.py +1 -0
- attune/cli/utils/data.py +242 -0
- attune/cli/utils/helpers.py +68 -0
- attune/cli_legacy.py +3957 -0
- attune/cli_minimal.py +1159 -0
- attune/cli_router.py +437 -0
- attune/cli_unified.py +814 -0
- attune/config/__init__.py +66 -0
- attune/config/xml_config.py +286 -0
- attune/config.py +545 -0
- attune/coordination.py +870 -0
- attune/core.py +1511 -0
- attune/core_modules/__init__.py +15 -0
- attune/cost_tracker.py +626 -0
- attune/dashboard/__init__.py +41 -0
- attune/dashboard/app.py +512 -0
- attune/dashboard/simple_server.py +435 -0
- attune/dashboard/standalone_server.py +547 -0
- attune/discovery.py +306 -0
- attune/emergence.py +306 -0
- attune/exceptions.py +123 -0
- attune/feedback_loops.py +373 -0
- attune/hot_reload/README.md +473 -0
- attune/hot_reload/__init__.py +62 -0
- attune/hot_reload/config.py +83 -0
- attune/hot_reload/integration.py +229 -0
- attune/hot_reload/reloader.py +298 -0
- attune/hot_reload/watcher.py +183 -0
- attune/hot_reload/websocket.py +177 -0
- attune/levels.py +577 -0
- attune/leverage_points.py +441 -0
- attune/logging_config.py +261 -0
- attune/mcp/__init__.py +10 -0
- attune/mcp/server.py +506 -0
- attune/memory/__init__.py +237 -0
- attune/memory/claude_memory.py +469 -0
- attune/memory/config.py +224 -0
- attune/memory/control_panel.py +1290 -0
- attune/memory/control_panel_support.py +145 -0
- attune/memory/cross_session.py +845 -0
- attune/memory/edges.py +179 -0
- attune/memory/encryption.py +159 -0
- attune/memory/file_session.py +770 -0
- attune/memory/graph.py +570 -0
- attune/memory/long_term.py +913 -0
- attune/memory/long_term_types.py +99 -0
- attune/memory/mixins/__init__.py +25 -0
- attune/memory/mixins/backend_init_mixin.py +249 -0
- attune/memory/mixins/capabilities_mixin.py +208 -0
- attune/memory/mixins/handoff_mixin.py +208 -0
- attune/memory/mixins/lifecycle_mixin.py +49 -0
- attune/memory/mixins/long_term_mixin.py +352 -0
- attune/memory/mixins/promotion_mixin.py +109 -0
- attune/memory/mixins/short_term_mixin.py +182 -0
- attune/memory/nodes.py +179 -0
- attune/memory/redis_bootstrap.py +540 -0
- attune/memory/security/__init__.py +31 -0
- attune/memory/security/audit_logger.py +932 -0
- attune/memory/security/pii_scrubber.py +640 -0
- attune/memory/security/secrets_detector.py +678 -0
- attune/memory/short_term.py +2192 -0
- attune/memory/simple_storage.py +302 -0
- attune/memory/storage/__init__.py +15 -0
- attune/memory/storage_backend.py +167 -0
- attune/memory/summary_index.py +583 -0
- attune/memory/types.py +446 -0
- attune/memory/unified.py +182 -0
- attune/meta_workflows/__init__.py +74 -0
- attune/meta_workflows/agent_creator.py +248 -0
- attune/meta_workflows/builtin_templates.py +567 -0
- attune/meta_workflows/cli_commands/__init__.py +56 -0
- attune/meta_workflows/cli_commands/agent_commands.py +321 -0
- attune/meta_workflows/cli_commands/analytics_commands.py +442 -0
- attune/meta_workflows/cli_commands/config_commands.py +232 -0
- attune/meta_workflows/cli_commands/memory_commands.py +182 -0
- attune/meta_workflows/cli_commands/template_commands.py +354 -0
- attune/meta_workflows/cli_commands/workflow_commands.py +382 -0
- attune/meta_workflows/cli_meta_workflows.py +59 -0
- attune/meta_workflows/form_engine.py +292 -0
- attune/meta_workflows/intent_detector.py +409 -0
- attune/meta_workflows/models.py +569 -0
- attune/meta_workflows/pattern_learner.py +738 -0
- attune/meta_workflows/plan_generator.py +384 -0
- attune/meta_workflows/session_context.py +397 -0
- attune/meta_workflows/template_registry.py +229 -0
- attune/meta_workflows/workflow.py +984 -0
- attune/metrics/__init__.py +12 -0
- attune/metrics/collector.py +31 -0
- attune/metrics/prompt_metrics.py +194 -0
- attune/models/__init__.py +172 -0
- attune/models/__main__.py +13 -0
- attune/models/adaptive_routing.py +437 -0
- attune/models/auth_cli.py +444 -0
- attune/models/auth_strategy.py +450 -0
- attune/models/cli.py +655 -0
- attune/models/empathy_executor.py +354 -0
- attune/models/executor.py +257 -0
- attune/models/fallback.py +762 -0
- attune/models/provider_config.py +282 -0
- attune/models/registry.py +472 -0
- attune/models/tasks.py +359 -0
- attune/models/telemetry/__init__.py +71 -0
- attune/models/telemetry/analytics.py +594 -0
- attune/models/telemetry/backend.py +196 -0
- attune/models/telemetry/data_models.py +431 -0
- attune/models/telemetry/storage.py +489 -0
- attune/models/token_estimator.py +420 -0
- attune/models/validation.py +280 -0
- attune/monitoring/__init__.py +52 -0
- attune/monitoring/alerts.py +946 -0
- attune/monitoring/alerts_cli.py +448 -0
- attune/monitoring/multi_backend.py +271 -0
- attune/monitoring/otel_backend.py +362 -0
- attune/optimization/__init__.py +19 -0
- attune/optimization/context_optimizer.py +272 -0
- attune/orchestration/__init__.py +67 -0
- attune/orchestration/agent_templates.py +707 -0
- attune/orchestration/config_store.py +499 -0
- attune/orchestration/execution_strategies.py +2111 -0
- attune/orchestration/meta_orchestrator.py +1168 -0
- attune/orchestration/pattern_learner.py +696 -0
- attune/orchestration/real_tools.py +931 -0
- attune/pattern_cache.py +187 -0
- attune/pattern_library.py +542 -0
- attune/patterns/debugging/all_patterns.json +81 -0
- attune/patterns/debugging/workflow_20260107_1770825e.json +77 -0
- attune/patterns/refactoring_memory.json +89 -0
- attune/persistence.py +564 -0
- attune/platform_utils.py +265 -0
- attune/plugins/__init__.py +28 -0
- attune/plugins/base.py +361 -0
- attune/plugins/registry.py +268 -0
- attune/project_index/__init__.py +32 -0
- attune/project_index/cli.py +335 -0
- attune/project_index/index.py +667 -0
- attune/project_index/models.py +504 -0
- attune/project_index/reports.py +474 -0
- attune/project_index/scanner.py +777 -0
- attune/project_index/scanner_parallel.py +291 -0
- attune/prompts/__init__.py +61 -0
- attune/prompts/config.py +77 -0
- attune/prompts/context.py +177 -0
- attune/prompts/parser.py +285 -0
- attune/prompts/registry.py +313 -0
- attune/prompts/templates.py +208 -0
- attune/redis_config.py +302 -0
- attune/redis_memory.py +799 -0
- attune/resilience/__init__.py +56 -0
- attune/resilience/circuit_breaker.py +256 -0
- attune/resilience/fallback.py +179 -0
- attune/resilience/health.py +300 -0
- attune/resilience/retry.py +209 -0
- attune/resilience/timeout.py +135 -0
- attune/routing/__init__.py +43 -0
- attune/routing/chain_executor.py +433 -0
- attune/routing/classifier.py +217 -0
- attune/routing/smart_router.py +234 -0
- attune/routing/workflow_registry.py +343 -0
- attune/scaffolding/README.md +589 -0
- attune/scaffolding/__init__.py +35 -0
- attune/scaffolding/__main__.py +14 -0
- attune/scaffolding/cli.py +240 -0
- attune/scaffolding/templates/base_wizard.py.jinja2 +121 -0
- attune/scaffolding/templates/coach_wizard.py.jinja2 +321 -0
- attune/scaffolding/templates/domain_wizard.py.jinja2 +408 -0
- attune/scaffolding/templates/linear_flow_wizard.py.jinja2 +203 -0
- attune/socratic/__init__.py +256 -0
- attune/socratic/ab_testing.py +958 -0
- attune/socratic/blueprint.py +533 -0
- attune/socratic/cli.py +703 -0
- attune/socratic/collaboration.py +1114 -0
- attune/socratic/domain_templates.py +924 -0
- attune/socratic/embeddings.py +738 -0
- attune/socratic/engine.py +794 -0
- attune/socratic/explainer.py +682 -0
- attune/socratic/feedback.py +772 -0
- attune/socratic/forms.py +629 -0
- attune/socratic/generator.py +732 -0
- attune/socratic/llm_analyzer.py +637 -0
- attune/socratic/mcp_server.py +702 -0
- attune/socratic/session.py +312 -0
- attune/socratic/storage.py +667 -0
- attune/socratic/success.py +730 -0
- attune/socratic/visual_editor.py +860 -0
- attune/socratic/web_ui.py +958 -0
- attune/telemetry/__init__.py +39 -0
- attune/telemetry/agent_coordination.py +475 -0
- attune/telemetry/agent_tracking.py +367 -0
- attune/telemetry/approval_gates.py +545 -0
- attune/telemetry/cli.py +1231 -0
- attune/telemetry/commands/__init__.py +14 -0
- attune/telemetry/commands/dashboard_commands.py +696 -0
- attune/telemetry/event_streaming.py +409 -0
- attune/telemetry/feedback_loop.py +567 -0
- attune/telemetry/usage_tracker.py +591 -0
- attune/templates.py +754 -0
- attune/test_generator/__init__.py +38 -0
- attune/test_generator/__main__.py +14 -0
- attune/test_generator/cli.py +234 -0
- attune/test_generator/generator.py +355 -0
- attune/test_generator/risk_analyzer.py +216 -0
- attune/test_generator/templates/unit_test.py.jinja2 +272 -0
- attune/tier_recommender.py +384 -0
- attune/tools.py +183 -0
- attune/trust/__init__.py +28 -0
- attune/trust/circuit_breaker.py +579 -0
- attune/trust_building.py +527 -0
- attune/validation/__init__.py +19 -0
- attune/validation/xml_validator.py +281 -0
- attune/vscode_bridge.py +173 -0
- attune/workflow_commands.py +780 -0
- attune/workflow_patterns/__init__.py +33 -0
- attune/workflow_patterns/behavior.py +249 -0
- attune/workflow_patterns/core.py +76 -0
- attune/workflow_patterns/output.py +99 -0
- attune/workflow_patterns/registry.py +255 -0
- attune/workflow_patterns/structural.py +288 -0
- attune/workflows/__init__.py +539 -0
- attune/workflows/autonomous_test_gen.py +1268 -0
- attune/workflows/base.py +2667 -0
- attune/workflows/batch_processing.py +342 -0
- attune/workflows/bug_predict.py +1084 -0
- attune/workflows/builder.py +273 -0
- attune/workflows/caching.py +253 -0
- attune/workflows/code_review.py +1048 -0
- attune/workflows/code_review_adapters.py +312 -0
- attune/workflows/code_review_pipeline.py +722 -0
- attune/workflows/config.py +645 -0
- attune/workflows/dependency_check.py +644 -0
- attune/workflows/document_gen/__init__.py +25 -0
- attune/workflows/document_gen/config.py +30 -0
- attune/workflows/document_gen/report_formatter.py +162 -0
- attune/workflows/document_gen/workflow.py +1426 -0
- attune/workflows/document_manager.py +216 -0
- attune/workflows/document_manager_README.md +134 -0
- attune/workflows/documentation_orchestrator.py +1205 -0
- attune/workflows/history.py +510 -0
- attune/workflows/keyboard_shortcuts/__init__.py +39 -0
- attune/workflows/keyboard_shortcuts/generators.py +391 -0
- attune/workflows/keyboard_shortcuts/parsers.py +416 -0
- attune/workflows/keyboard_shortcuts/prompts.py +295 -0
- attune/workflows/keyboard_shortcuts/schema.py +193 -0
- attune/workflows/keyboard_shortcuts/workflow.py +509 -0
- attune/workflows/llm_base.py +363 -0
- attune/workflows/manage_docs.py +87 -0
- attune/workflows/manage_docs_README.md +134 -0
- attune/workflows/manage_documentation.py +821 -0
- attune/workflows/new_sample_workflow1.py +149 -0
- attune/workflows/new_sample_workflow1_README.md +150 -0
- attune/workflows/orchestrated_health_check.py +849 -0
- attune/workflows/orchestrated_release_prep.py +600 -0
- attune/workflows/output.py +413 -0
- attune/workflows/perf_audit.py +863 -0
- attune/workflows/pr_review.py +762 -0
- attune/workflows/progress.py +785 -0
- attune/workflows/progress_server.py +322 -0
- attune/workflows/progressive/README 2.md +454 -0
- attune/workflows/progressive/README.md +454 -0
- attune/workflows/progressive/__init__.py +82 -0
- attune/workflows/progressive/cli.py +219 -0
- attune/workflows/progressive/core.py +488 -0
- attune/workflows/progressive/orchestrator.py +723 -0
- attune/workflows/progressive/reports.py +520 -0
- attune/workflows/progressive/telemetry.py +274 -0
- attune/workflows/progressive/test_gen.py +495 -0
- attune/workflows/progressive/workflow.py +589 -0
- attune/workflows/refactor_plan.py +694 -0
- attune/workflows/release_prep.py +895 -0
- attune/workflows/release_prep_crew.py +969 -0
- attune/workflows/research_synthesis.py +404 -0
- attune/workflows/routing.py +168 -0
- attune/workflows/secure_release.py +593 -0
- attune/workflows/security_adapters.py +297 -0
- attune/workflows/security_audit.py +1329 -0
- attune/workflows/security_audit_phase3.py +355 -0
- attune/workflows/seo_optimization.py +633 -0
- attune/workflows/step_config.py +234 -0
- attune/workflows/telemetry_mixin.py +269 -0
- attune/workflows/test5.py +125 -0
- attune/workflows/test5_README.md +158 -0
- attune/workflows/test_coverage_boost_crew.py +849 -0
- attune/workflows/test_gen/__init__.py +52 -0
- attune/workflows/test_gen/ast_analyzer.py +249 -0
- attune/workflows/test_gen/config.py +88 -0
- attune/workflows/test_gen/data_models.py +38 -0
- attune/workflows/test_gen/report_formatter.py +289 -0
- attune/workflows/test_gen/test_templates.py +381 -0
- attune/workflows/test_gen/workflow.py +655 -0
- attune/workflows/test_gen.py +54 -0
- attune/workflows/test_gen_behavioral.py +477 -0
- attune/workflows/test_gen_parallel.py +341 -0
- attune/workflows/test_lifecycle.py +526 -0
- attune/workflows/test_maintenance.py +627 -0
- attune/workflows/test_maintenance_cli.py +590 -0
- attune/workflows/test_maintenance_crew.py +840 -0
- attune/workflows/test_runner.py +622 -0
- attune/workflows/tier_tracking.py +531 -0
- attune/workflows/xml_enhanced_crew.py +285 -0
- attune_ai-2.0.0.dist-info/METADATA +1026 -0
- attune_ai-2.0.0.dist-info/RECORD +457 -0
- attune_ai-2.0.0.dist-info/WHEEL +5 -0
- attune_ai-2.0.0.dist-info/entry_points.txt +26 -0
- attune_ai-2.0.0.dist-info/licenses/LICENSE +201 -0
- attune_ai-2.0.0.dist-info/licenses/LICENSE_CHANGE_ANNOUNCEMENT.md +101 -0
- attune_ai-2.0.0.dist-info/top_level.txt +5 -0
- attune_healthcare/__init__.py +13 -0
- attune_healthcare/monitors/__init__.py +9 -0
- attune_healthcare/monitors/clinical_protocol_monitor.py +315 -0
- attune_healthcare/monitors/monitoring/__init__.py +44 -0
- attune_healthcare/monitors/monitoring/protocol_checker.py +300 -0
- attune_healthcare/monitors/monitoring/protocol_loader.py +214 -0
- attune_healthcare/monitors/monitoring/sensor_parsers.py +306 -0
- attune_healthcare/monitors/monitoring/trajectory_analyzer.py +389 -0
- attune_llm/README.md +553 -0
- attune_llm/__init__.py +28 -0
- attune_llm/agent_factory/__init__.py +53 -0
- attune_llm/agent_factory/adapters/__init__.py +85 -0
- attune_llm/agent_factory/adapters/autogen_adapter.py +312 -0
- attune_llm/agent_factory/adapters/crewai_adapter.py +483 -0
- attune_llm/agent_factory/adapters/haystack_adapter.py +298 -0
- attune_llm/agent_factory/adapters/langchain_adapter.py +362 -0
- attune_llm/agent_factory/adapters/langgraph_adapter.py +333 -0
- attune_llm/agent_factory/adapters/native.py +228 -0
- attune_llm/agent_factory/adapters/wizard_adapter.py +423 -0
- attune_llm/agent_factory/base.py +305 -0
- attune_llm/agent_factory/crews/__init__.py +67 -0
- attune_llm/agent_factory/crews/code_review.py +1113 -0
- attune_llm/agent_factory/crews/health_check.py +1262 -0
- attune_llm/agent_factory/crews/refactoring.py +1128 -0
- attune_llm/agent_factory/crews/security_audit.py +1018 -0
- attune_llm/agent_factory/decorators.py +287 -0
- attune_llm/agent_factory/factory.py +558 -0
- attune_llm/agent_factory/framework.py +193 -0
- attune_llm/agent_factory/memory_integration.py +328 -0
- attune_llm/agent_factory/resilient.py +320 -0
- attune_llm/agents_md/__init__.py +22 -0
- attune_llm/agents_md/loader.py +218 -0
- attune_llm/agents_md/parser.py +271 -0
- attune_llm/agents_md/registry.py +307 -0
- attune_llm/claude_memory.py +466 -0
- attune_llm/cli/__init__.py +8 -0
- attune_llm/cli/sync_claude.py +487 -0
- attune_llm/code_health.py +1313 -0
- attune_llm/commands/__init__.py +51 -0
- attune_llm/commands/context.py +375 -0
- attune_llm/commands/loader.py +301 -0
- attune_llm/commands/models.py +231 -0
- attune_llm/commands/parser.py +371 -0
- attune_llm/commands/registry.py +429 -0
- attune_llm/config/__init__.py +29 -0
- attune_llm/config/unified.py +291 -0
- attune_llm/context/__init__.py +22 -0
- attune_llm/context/compaction.py +455 -0
- attune_llm/context/manager.py +434 -0
- attune_llm/contextual_patterns.py +361 -0
- attune_llm/core.py +907 -0
- attune_llm/git_pattern_extractor.py +435 -0
- attune_llm/hooks/__init__.py +24 -0
- attune_llm/hooks/config.py +306 -0
- attune_llm/hooks/executor.py +289 -0
- attune_llm/hooks/registry.py +302 -0
- attune_llm/hooks/scripts/__init__.py +39 -0
- attune_llm/hooks/scripts/evaluate_session.py +201 -0
- attune_llm/hooks/scripts/first_time_init.py +285 -0
- attune_llm/hooks/scripts/pre_compact.py +207 -0
- attune_llm/hooks/scripts/session_end.py +183 -0
- attune_llm/hooks/scripts/session_start.py +163 -0
- attune_llm/hooks/scripts/suggest_compact.py +225 -0
- attune_llm/learning/__init__.py +30 -0
- attune_llm/learning/evaluator.py +438 -0
- attune_llm/learning/extractor.py +514 -0
- attune_llm/learning/storage.py +560 -0
- attune_llm/levels.py +227 -0
- attune_llm/pattern_confidence.py +414 -0
- attune_llm/pattern_resolver.py +272 -0
- attune_llm/pattern_summary.py +350 -0
- attune_llm/providers.py +967 -0
- attune_llm/routing/__init__.py +32 -0
- attune_llm/routing/model_router.py +362 -0
- attune_llm/security/IMPLEMENTATION_SUMMARY.md +413 -0
- attune_llm/security/PHASE2_COMPLETE.md +384 -0
- attune_llm/security/PHASE2_SECRETS_DETECTOR_COMPLETE.md +271 -0
- attune_llm/security/QUICK_REFERENCE.md +316 -0
- attune_llm/security/README.md +262 -0
- attune_llm/security/__init__.py +62 -0
- attune_llm/security/audit_logger.py +929 -0
- attune_llm/security/audit_logger_example.py +152 -0
- attune_llm/security/pii_scrubber.py +640 -0
- attune_llm/security/secrets_detector.py +678 -0
- attune_llm/security/secrets_detector_example.py +304 -0
- attune_llm/security/secure_memdocs.py +1192 -0
- attune_llm/security/secure_memdocs_example.py +278 -0
- attune_llm/session_status.py +745 -0
- attune_llm/state.py +246 -0
- attune_llm/utils/__init__.py +5 -0
- attune_llm/utils/tokens.py +349 -0
- attune_software/SOFTWARE_PLUGIN_README.md +57 -0
- attune_software/__init__.py +13 -0
- attune_software/cli/__init__.py +120 -0
- attune_software/cli/inspect.py +362 -0
- attune_software/cli.py +574 -0
- attune_software/plugin.py +188 -0
- workflow_scaffolding/__init__.py +11 -0
- workflow_scaffolding/__main__.py +12 -0
- workflow_scaffolding/cli.py +206 -0
- workflow_scaffolding/generator.py +265 -0
|
@@ -0,0 +1,1018 @@
|
|
|
1
|
+
"""Security Audit Crew
|
|
2
|
+
|
|
3
|
+
A multi-agent crew that performs comprehensive security audits.
|
|
4
|
+
Demonstrates CrewAI's hierarchical collaboration patterns with:
|
|
5
|
+
- 5 specialized agents with distinct roles
|
|
6
|
+
- Hierarchical task delegation from Security Lead
|
|
7
|
+
- Memory Graph integration for cross-analysis learning
|
|
8
|
+
- Structured output with severity scoring
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
from attune_llm.agent_factory.crews import SecurityAuditCrew
|
|
12
|
+
|
|
13
|
+
crew = SecurityAuditCrew(api_key="...")
|
|
14
|
+
report = await crew.audit("path/to/codebase")
|
|
15
|
+
|
|
16
|
+
print(f"Found {len(report.findings)} security issues")
|
|
17
|
+
for finding in report.critical_findings:
|
|
18
|
+
print(f" - {finding.title}: {finding.remediation}")
|
|
19
|
+
|
|
20
|
+
Copyright 2025 Smart-AI-Memory
|
|
21
|
+
Licensed under Fair Source License 0.9
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import logging
|
|
25
|
+
from dataclasses import dataclass, field
|
|
26
|
+
from enum import Enum
|
|
27
|
+
from typing import Any
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Severity(Enum):
|
|
33
|
+
"""Security finding severity levels."""
|
|
34
|
+
|
|
35
|
+
CRITICAL = "critical"
|
|
36
|
+
HIGH = "high"
|
|
37
|
+
MEDIUM = "medium"
|
|
38
|
+
LOW = "low"
|
|
39
|
+
INFO = "info"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class FindingCategory(Enum):
|
|
43
|
+
"""Security finding categories (OWASP-aligned)."""
|
|
44
|
+
|
|
45
|
+
INJECTION = "injection"
|
|
46
|
+
BROKEN_AUTH = "broken_authentication"
|
|
47
|
+
SENSITIVE_DATA = "sensitive_data_exposure"
|
|
48
|
+
XXE = "xml_external_entities"
|
|
49
|
+
BROKEN_ACCESS = "broken_access_control"
|
|
50
|
+
MISCONFIGURATION = "security_misconfiguration"
|
|
51
|
+
XSS = "cross_site_scripting"
|
|
52
|
+
INSECURE_DESERIALIZATION = "insecure_deserialization"
|
|
53
|
+
VULNERABLE_COMPONENTS = "vulnerable_components"
|
|
54
|
+
INSUFFICIENT_LOGGING = "insufficient_logging"
|
|
55
|
+
OTHER = "other"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass
|
|
59
|
+
class SecurityFinding:
|
|
60
|
+
"""A single security finding from the audit."""
|
|
61
|
+
|
|
62
|
+
title: str
|
|
63
|
+
description: str
|
|
64
|
+
severity: Severity
|
|
65
|
+
category: FindingCategory
|
|
66
|
+
file_path: str | None = None
|
|
67
|
+
line_number: int | None = None
|
|
68
|
+
code_snippet: str | None = None
|
|
69
|
+
remediation: str | None = None
|
|
70
|
+
cwe_id: str | None = None
|
|
71
|
+
cvss_score: float | None = None
|
|
72
|
+
confidence: float = 1.0
|
|
73
|
+
metadata: dict = field(default_factory=dict)
|
|
74
|
+
|
|
75
|
+
def to_dict(self) -> dict:
|
|
76
|
+
"""Convert finding to dictionary."""
|
|
77
|
+
return {
|
|
78
|
+
"title": self.title,
|
|
79
|
+
"description": self.description,
|
|
80
|
+
"severity": self.severity.value,
|
|
81
|
+
"category": self.category.value,
|
|
82
|
+
"file_path": self.file_path,
|
|
83
|
+
"line_number": self.line_number,
|
|
84
|
+
"code_snippet": self.code_snippet,
|
|
85
|
+
"remediation": self.remediation,
|
|
86
|
+
"cwe_id": self.cwe_id,
|
|
87
|
+
"cvss_score": self.cvss_score,
|
|
88
|
+
"confidence": self.confidence,
|
|
89
|
+
"metadata": self.metadata,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@dataclass
|
|
94
|
+
class SecurityReport:
|
|
95
|
+
"""Complete security audit report."""
|
|
96
|
+
|
|
97
|
+
target: str
|
|
98
|
+
findings: list[SecurityFinding]
|
|
99
|
+
summary: str = ""
|
|
100
|
+
audit_duration_seconds: float = 0.0
|
|
101
|
+
agents_used: list[str] = field(default_factory=list)
|
|
102
|
+
memory_graph_hits: int = 0
|
|
103
|
+
metadata: dict = field(default_factory=dict)
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def critical_findings(self) -> list[SecurityFinding]:
|
|
107
|
+
"""Get critical severity findings."""
|
|
108
|
+
return [f for f in self.findings if f.severity == Severity.CRITICAL]
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def high_findings(self) -> list[SecurityFinding]:
|
|
112
|
+
"""Get high severity findings."""
|
|
113
|
+
return [f for f in self.findings if f.severity == Severity.HIGH]
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def findings_by_category(self) -> dict[str, list[SecurityFinding]]:
|
|
117
|
+
"""Group findings by category."""
|
|
118
|
+
result: dict[str, list[SecurityFinding]] = {}
|
|
119
|
+
for finding in self.findings:
|
|
120
|
+
cat = finding.category.value
|
|
121
|
+
if cat not in result:
|
|
122
|
+
result[cat] = []
|
|
123
|
+
result[cat].append(finding)
|
|
124
|
+
return result
|
|
125
|
+
|
|
126
|
+
@property
|
|
127
|
+
def risk_score(self) -> float:
|
|
128
|
+
"""Calculate overall risk score (0-100)."""
|
|
129
|
+
if not self.findings:
|
|
130
|
+
return 0.0
|
|
131
|
+
|
|
132
|
+
weights = {
|
|
133
|
+
Severity.CRITICAL: 25,
|
|
134
|
+
Severity.HIGH: 15,
|
|
135
|
+
Severity.MEDIUM: 5,
|
|
136
|
+
Severity.LOW: 2,
|
|
137
|
+
Severity.INFO: 0.5,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
total = sum(weights[f.severity] * f.confidence for f in self.findings)
|
|
141
|
+
return min(100.0, total)
|
|
142
|
+
|
|
143
|
+
def to_dict(self) -> dict:
|
|
144
|
+
"""Convert report to dictionary."""
|
|
145
|
+
return {
|
|
146
|
+
"target": self.target,
|
|
147
|
+
"findings": [f.to_dict() for f in self.findings],
|
|
148
|
+
"summary": self.summary,
|
|
149
|
+
"audit_duration_seconds": self.audit_duration_seconds,
|
|
150
|
+
"agents_used": self.agents_used,
|
|
151
|
+
"memory_graph_hits": self.memory_graph_hits,
|
|
152
|
+
"risk_score": self.risk_score,
|
|
153
|
+
"finding_counts": {
|
|
154
|
+
"critical": len(self.critical_findings),
|
|
155
|
+
"high": len(self.high_findings),
|
|
156
|
+
"total": len(self.findings),
|
|
157
|
+
},
|
|
158
|
+
"metadata": self.metadata,
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@dataclass
|
|
163
|
+
class SecurityAuditConfig:
|
|
164
|
+
"""Configuration for security audit crew."""
|
|
165
|
+
|
|
166
|
+
# API Configuration
|
|
167
|
+
provider: str = "anthropic"
|
|
168
|
+
api_key: str | None = None
|
|
169
|
+
|
|
170
|
+
# Scan Configuration
|
|
171
|
+
scan_depth: str = "standard" # "quick", "standard", "thorough"
|
|
172
|
+
include_patterns: list[str] = field(
|
|
173
|
+
default_factory=lambda: ["*.py", "*.js", "*.ts", "*.java", "*.go"],
|
|
174
|
+
)
|
|
175
|
+
exclude_patterns: list[str] = field(
|
|
176
|
+
default_factory=lambda: ["*test*", "*spec*", "node_modules/*", "venv/*"],
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
# Memory Graph
|
|
180
|
+
memory_graph_enabled: bool = True
|
|
181
|
+
memory_graph_path: str = "patterns/security_memory.json"
|
|
182
|
+
|
|
183
|
+
# Agent Tiers
|
|
184
|
+
lead_tier: str = "premium"
|
|
185
|
+
hunter_tier: str = "capable"
|
|
186
|
+
assessor_tier: str = "capable"
|
|
187
|
+
remediation_tier: str = "premium"
|
|
188
|
+
compliance_tier: str = "cheap"
|
|
189
|
+
|
|
190
|
+
# Resilience
|
|
191
|
+
resilience_enabled: bool = True
|
|
192
|
+
timeout_seconds: float = 300.0
|
|
193
|
+
|
|
194
|
+
# XML Prompts
|
|
195
|
+
xml_prompts_enabled: bool = True
|
|
196
|
+
xml_schema_version: str = "1.0"
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
# XML Prompt Templates for Security Audit Agents
|
|
200
|
+
XML_PROMPT_TEMPLATES = {
|
|
201
|
+
"security_lead": """<agent role="security_lead" version="{schema_version}">
|
|
202
|
+
<identity>
|
|
203
|
+
<role>Security Audit Lead</role>
|
|
204
|
+
<expertise>Security coordination, risk prioritization, executive reporting</expertise>
|
|
205
|
+
</identity>
|
|
206
|
+
|
|
207
|
+
<goal>
|
|
208
|
+
Coordinate the security audit team to identify and prioritize vulnerabilities.
|
|
209
|
+
Synthesize findings into an actionable security report.
|
|
210
|
+
</goal>
|
|
211
|
+
|
|
212
|
+
<instructions>
|
|
213
|
+
<step>Coordinate the security audit team and assign analysis tasks</step>
|
|
214
|
+
<step>Review and deduplicate findings from all specialists</step>
|
|
215
|
+
<step>Prioritize findings by risk score and exploitability</step>
|
|
216
|
+
<step>Calculate overall risk score for the target</step>
|
|
217
|
+
<step>Generate executive summary with key recommendations</step>
|
|
218
|
+
</instructions>
|
|
219
|
+
|
|
220
|
+
<constraints>
|
|
221
|
+
<rule>Focus on actionable, exploitable vulnerabilities</rule>
|
|
222
|
+
<rule>Minimize false positives through validation</rule>
|
|
223
|
+
<rule>Provide clear risk context for each finding</rule>
|
|
224
|
+
<rule>Include both technical and business impact</rule>
|
|
225
|
+
</constraints>
|
|
226
|
+
|
|
227
|
+
<output_format>
|
|
228
|
+
<section name="summary">Executive summary of security posture</section>
|
|
229
|
+
<section name="risk_score">Overall risk score 0-100</section>
|
|
230
|
+
<section name="critical_findings">Vulnerabilities requiring immediate attention</section>
|
|
231
|
+
<section name="recommendations">Prioritized remediation roadmap</section>
|
|
232
|
+
</output_format>
|
|
233
|
+
</agent>""",
|
|
234
|
+
"vulnerability_hunter": """<agent role="vulnerability_hunter" version="{schema_version}">
|
|
235
|
+
<identity>
|
|
236
|
+
<role>Vulnerability Hunter</role>
|
|
237
|
+
<expertise>OWASP Top 10, penetration testing, vulnerability identification</expertise>
|
|
238
|
+
</identity>
|
|
239
|
+
|
|
240
|
+
<goal>
|
|
241
|
+
Identify security vulnerabilities in code and configuration.
|
|
242
|
+
</goal>
|
|
243
|
+
|
|
244
|
+
<instructions>
|
|
245
|
+
<step>Scan for OWASP Top 10 vulnerabilities</step>
|
|
246
|
+
<step>Identify injection points (SQL, command, LDAP)</step>
|
|
247
|
+
<step>Check for authentication and authorization flaws</step>
|
|
248
|
+
<step>Review cryptographic implementations</step>
|
|
249
|
+
<step>Detect hardcoded secrets and credentials</step>
|
|
250
|
+
<step>Document each finding with file, line, and evidence</step>
|
|
251
|
+
</instructions>
|
|
252
|
+
|
|
253
|
+
<constraints>
|
|
254
|
+
<rule>Focus on exploitable vulnerabilities</rule>
|
|
255
|
+
<rule>Provide proof-of-concept or attack vector</rule>
|
|
256
|
+
<rule>Include file path and line number</rule>
|
|
257
|
+
<rule>Rate severity using CVSS methodology</rule>
|
|
258
|
+
</constraints>
|
|
259
|
+
|
|
260
|
+
<owasp_categories>
|
|
261
|
+
<category>A01 - Broken Access Control</category>
|
|
262
|
+
<category>A02 - Cryptographic Failures</category>
|
|
263
|
+
<category>A03 - Injection</category>
|
|
264
|
+
<category>A04 - Insecure Design</category>
|
|
265
|
+
<category>A05 - Security Misconfiguration</category>
|
|
266
|
+
<category>A06 - Vulnerable Components</category>
|
|
267
|
+
<category>A07 - Auth Failures</category>
|
|
268
|
+
<category>A08 - Software Integrity Failures</category>
|
|
269
|
+
<category>A09 - Logging Failures</category>
|
|
270
|
+
<category>A10 - SSRF</category>
|
|
271
|
+
</owasp_categories>
|
|
272
|
+
|
|
273
|
+
<output_format>
|
|
274
|
+
<section name="findings">Vulnerabilities with severity, location, and evidence</section>
|
|
275
|
+
<section name="summary">Vulnerability distribution summary</section>
|
|
276
|
+
</output_format>
|
|
277
|
+
</agent>""",
|
|
278
|
+
"risk_assessor": """<agent role="risk_assessor" version="{schema_version}">
|
|
279
|
+
<identity>
|
|
280
|
+
<role>Risk Assessor</role>
|
|
281
|
+
<expertise>CVSS scoring, risk analysis, threat modeling</expertise>
|
|
282
|
+
</identity>
|
|
283
|
+
|
|
284
|
+
<goal>
|
|
285
|
+
Assess the risk level of identified vulnerabilities.
|
|
286
|
+
</goal>
|
|
287
|
+
|
|
288
|
+
<instructions>
|
|
289
|
+
<step>Calculate CVSS scores for each vulnerability</step>
|
|
290
|
+
<step>Assess exploitability and attack complexity</step>
|
|
291
|
+
<step>Evaluate blast radius and data sensitivity</step>
|
|
292
|
+
<step>Consider existing mitigating controls</step>
|
|
293
|
+
<step>Prioritize by business impact</step>
|
|
294
|
+
<step>Identify attack chains and compound risks</step>
|
|
295
|
+
</instructions>
|
|
296
|
+
|
|
297
|
+
<constraints>
|
|
298
|
+
<rule>Use CVSS 3.1 methodology consistently</rule>
|
|
299
|
+
<rule>Consider environmental factors</rule>
|
|
300
|
+
<rule>Identify dependencies between findings</rule>
|
|
301
|
+
<rule>Provide confidence levels for assessments</rule>
|
|
302
|
+
</constraints>
|
|
303
|
+
|
|
304
|
+
<cvss_vectors>
|
|
305
|
+
<metric name="AV">Attack Vector (Network, Adjacent, Local, Physical)</metric>
|
|
306
|
+
<metric name="AC">Attack Complexity (Low, High)</metric>
|
|
307
|
+
<metric name="PR">Privileges Required (None, Low, High)</metric>
|
|
308
|
+
<metric name="UI">User Interaction (None, Required)</metric>
|
|
309
|
+
<metric name="S">Scope (Unchanged, Changed)</metric>
|
|
310
|
+
<metric name="C">Confidentiality Impact (None, Low, High)</metric>
|
|
311
|
+
<metric name="I">Integrity Impact (None, Low, High)</metric>
|
|
312
|
+
<metric name="A">Availability Impact (None, Low, High)</metric>
|
|
313
|
+
</cvss_vectors>
|
|
314
|
+
|
|
315
|
+
<output_format>
|
|
316
|
+
<section name="assessments">Risk assessments with CVSS scores</section>
|
|
317
|
+
<section name="summary">Overall risk level and key concerns</section>
|
|
318
|
+
</output_format>
|
|
319
|
+
</agent>""",
|
|
320
|
+
"remediation_expert": """<agent role="remediation_expert" version="{schema_version}">
|
|
321
|
+
<identity>
|
|
322
|
+
<role>Remediation Expert</role>
|
|
323
|
+
<expertise>Secure coding, security engineering, fix implementation</expertise>
|
|
324
|
+
</identity>
|
|
325
|
+
|
|
326
|
+
<goal>
|
|
327
|
+
Generate actionable remediation strategies for each vulnerability.
|
|
328
|
+
</goal>
|
|
329
|
+
|
|
330
|
+
<instructions>
|
|
331
|
+
<step>Analyze root cause of each vulnerability</step>
|
|
332
|
+
<step>Design fix strategy with code examples</step>
|
|
333
|
+
<step>Consider backwards compatibility</step>
|
|
334
|
+
<step>Prioritize fixes by effort vs impact</step>
|
|
335
|
+
<step>Identify quick wins and long-term improvements</step>
|
|
336
|
+
<step>Suggest testing approach for each fix</step>
|
|
337
|
+
</instructions>
|
|
338
|
+
|
|
339
|
+
<constraints>
|
|
340
|
+
<rule>Provide complete, copy-pasteable code fixes</rule>
|
|
341
|
+
<rule>Consider side effects and regressions</rule>
|
|
342
|
+
<rule>Include before/after code snippets</rule>
|
|
343
|
+
<rule>Reference security best practices</rule>
|
|
344
|
+
</constraints>
|
|
345
|
+
|
|
346
|
+
<remediation_types>
|
|
347
|
+
<type>Code Fix - Direct code changes</type>
|
|
348
|
+
<type>Configuration - Settings/environment changes</type>
|
|
349
|
+
<type>Architecture - Structural improvements</type>
|
|
350
|
+
<type>Dependency - Library updates/replacements</type>
|
|
351
|
+
<type>Process - Development workflow changes</type>
|
|
352
|
+
</remediation_types>
|
|
353
|
+
|
|
354
|
+
<output_format>
|
|
355
|
+
<section name="remediations">Fix strategies with code examples</section>
|
|
356
|
+
<section name="summary">Remediation roadmap by priority</section>
|
|
357
|
+
</output_format>
|
|
358
|
+
</agent>""",
|
|
359
|
+
"compliance_mapper": """<agent role="compliance_mapper" version="{schema_version}">
|
|
360
|
+
<identity>
|
|
361
|
+
<role>Compliance Mapper</role>
|
|
362
|
+
<expertise>Security standards, CWE/CVE mapping, regulatory compliance</expertise>
|
|
363
|
+
</identity>
|
|
364
|
+
|
|
365
|
+
<goal>
|
|
366
|
+
Map vulnerabilities to standards and identify compliance implications.
|
|
367
|
+
</goal>
|
|
368
|
+
|
|
369
|
+
<instructions>
|
|
370
|
+
<step>Map each finding to CWE identifiers</step>
|
|
371
|
+
<step>Check for related CVEs in dependencies</step>
|
|
372
|
+
<step>Identify OWASP category alignment</step>
|
|
373
|
+
<step>Assess regulatory compliance impact (GDPR, HIPAA, PCI-DSS)</step>
|
|
374
|
+
<step>Document audit trail requirements</step>
|
|
375
|
+
<step>Suggest compliance-focused remediation priorities</step>
|
|
376
|
+
</instructions>
|
|
377
|
+
|
|
378
|
+
<constraints>
|
|
379
|
+
<rule>Use official CWE/CVE identifiers</rule>
|
|
380
|
+
<rule>Consider multiple compliance frameworks</rule>
|
|
381
|
+
<rule>Highlight mandatory vs recommended fixes</rule>
|
|
382
|
+
<rule>Include references to standards</rule>
|
|
383
|
+
</constraints>
|
|
384
|
+
|
|
385
|
+
<compliance_frameworks>
|
|
386
|
+
<framework>OWASP Top 10</framework>
|
|
387
|
+
<framework>CWE/SANS Top 25</framework>
|
|
388
|
+
<framework>PCI-DSS</framework>
|
|
389
|
+
<framework>HIPAA</framework>
|
|
390
|
+
<framework>GDPR</framework>
|
|
391
|
+
<framework>SOC 2</framework>
|
|
392
|
+
</compliance_frameworks>
|
|
393
|
+
|
|
394
|
+
<output_format>
|
|
395
|
+
<section name="mappings">CWE/CVE mappings for each finding</section>
|
|
396
|
+
<section name="compliance">Regulatory implications and requirements</section>
|
|
397
|
+
<section name="summary">Compliance status overview</section>
|
|
398
|
+
</output_format>
|
|
399
|
+
</agent>""",
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
class SecurityAuditCrew:
|
|
404
|
+
"""Multi-agent crew for comprehensive security audits.
|
|
405
|
+
|
|
406
|
+
The crew consists of 5 specialized agents:
|
|
407
|
+
|
|
408
|
+
1. **Security Lead** (Coordinator)
|
|
409
|
+
- Orchestrates the team
|
|
410
|
+
- Prioritizes and deduplicates findings
|
|
411
|
+
- Generates executive summary
|
|
412
|
+
- Model: Premium tier
|
|
413
|
+
|
|
414
|
+
2. **Vulnerability Hunter** (Security Analyst)
|
|
415
|
+
- Scans for OWASP Top 10 vulnerabilities
|
|
416
|
+
- Identifies injection, XSS, auth issues
|
|
417
|
+
- Model: Capable tier
|
|
418
|
+
|
|
419
|
+
3. **Risk Assessor** (Risk Analyst)
|
|
420
|
+
- Scores severity using CVSS methodology
|
|
421
|
+
- Assesses blast radius and exploitability
|
|
422
|
+
- Model: Capable tier
|
|
423
|
+
|
|
424
|
+
4. **Remediation Expert** (Security Engineer)
|
|
425
|
+
- Generates fix strategies with code examples
|
|
426
|
+
- Prioritizes based on effort vs. impact
|
|
427
|
+
- Model: Premium tier
|
|
428
|
+
|
|
429
|
+
5. **Compliance Mapper** (Compliance Officer)
|
|
430
|
+
- Maps findings to CWE, CVE, OWASP
|
|
431
|
+
- Identifies compliance implications
|
|
432
|
+
- Model: Cheap tier
|
|
433
|
+
|
|
434
|
+
Example:
|
|
435
|
+
crew = SecurityAuditCrew(api_key="...")
|
|
436
|
+
report = await crew.audit("./src")
|
|
437
|
+
|
|
438
|
+
# Access findings
|
|
439
|
+
for finding in report.critical_findings:
|
|
440
|
+
print(f"{finding.title}: {finding.remediation}")
|
|
441
|
+
|
|
442
|
+
# Get risk score
|
|
443
|
+
print(f"Risk Score: {report.risk_score}/100")
|
|
444
|
+
|
|
445
|
+
"""
|
|
446
|
+
|
|
447
|
+
def __init__(self, config: SecurityAuditConfig | None = None, **kwargs):
|
|
448
|
+
"""Initialize the Security Audit Crew.
|
|
449
|
+
|
|
450
|
+
Args:
|
|
451
|
+
config: SecurityAuditConfig or pass individual params as kwargs
|
|
452
|
+
**kwargs: Individual config parameters (api_key, provider, etc.)
|
|
453
|
+
|
|
454
|
+
"""
|
|
455
|
+
if config:
|
|
456
|
+
self.config = config
|
|
457
|
+
else:
|
|
458
|
+
self.config = SecurityAuditConfig(**kwargs)
|
|
459
|
+
|
|
460
|
+
self._factory: Any = None
|
|
461
|
+
self._agents: dict[str, Any] = {}
|
|
462
|
+
self._workflow: Any = None
|
|
463
|
+
self._graph: Any = None
|
|
464
|
+
self._initialized = False
|
|
465
|
+
|
|
466
|
+
def _render_xml_prompt(self, template_key: str) -> str:
|
|
467
|
+
"""Render XML prompt template with config values."""
|
|
468
|
+
template = XML_PROMPT_TEMPLATES.get(template_key, "")
|
|
469
|
+
return template.format(schema_version=self.config.xml_schema_version)
|
|
470
|
+
|
|
471
|
+
def _get_system_prompt(self, agent_key: str, fallback: str) -> str:
|
|
472
|
+
"""Get system prompt - XML if enabled, fallback otherwise."""
|
|
473
|
+
if self.config.xml_prompts_enabled:
|
|
474
|
+
return self._render_xml_prompt(agent_key)
|
|
475
|
+
return fallback
|
|
476
|
+
|
|
477
|
+
async def _initialize(self) -> None:
|
|
478
|
+
"""Lazy initialization of agents and workflow."""
|
|
479
|
+
if self._initialized:
|
|
480
|
+
return
|
|
481
|
+
|
|
482
|
+
from attune_llm.agent_factory import AgentFactory, Framework
|
|
483
|
+
|
|
484
|
+
# Check if CrewAI is available
|
|
485
|
+
try:
|
|
486
|
+
from attune_llm.agent_factory.adapters.crewai_adapter import _check_crewai
|
|
487
|
+
|
|
488
|
+
use_crewai = _check_crewai()
|
|
489
|
+
except ImportError:
|
|
490
|
+
use_crewai = False
|
|
491
|
+
|
|
492
|
+
# Use CrewAI if available, otherwise fall back to Native
|
|
493
|
+
framework = Framework.CREWAI if use_crewai else Framework.NATIVE
|
|
494
|
+
|
|
495
|
+
self._factory = AgentFactory(
|
|
496
|
+
framework=framework,
|
|
497
|
+
provider=self.config.provider,
|
|
498
|
+
api_key=self.config.api_key,
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
# Initialize Memory Graph if enabled
|
|
502
|
+
if self.config.memory_graph_enabled:
|
|
503
|
+
try:
|
|
504
|
+
from attune.memory import MemoryGraph
|
|
505
|
+
|
|
506
|
+
self._graph = MemoryGraph(path=self.config.memory_graph_path)
|
|
507
|
+
except ImportError:
|
|
508
|
+
logger.warning("Memory Graph not available, continuing without it")
|
|
509
|
+
|
|
510
|
+
# Create the 5 specialized agents
|
|
511
|
+
await self._create_agents()
|
|
512
|
+
|
|
513
|
+
# Create hierarchical workflow
|
|
514
|
+
await self._create_workflow()
|
|
515
|
+
|
|
516
|
+
self._initialized = True
|
|
517
|
+
|
|
518
|
+
async def _create_agents(self) -> None:
|
|
519
|
+
"""Create the 5 specialized security agents."""
|
|
520
|
+
# 1. Security Lead (Coordinator)
|
|
521
|
+
lead_fallback = """You are the Security Lead, a senior security architect.
|
|
522
|
+
|
|
523
|
+
Your responsibilities:
|
|
524
|
+
1. Coordinate the security audit team
|
|
525
|
+
2. Prioritize findings based on business impact
|
|
526
|
+
3. Deduplicate overlapping findings
|
|
527
|
+
4. Generate executive summaries
|
|
528
|
+
5. Ensure comprehensive coverage
|
|
529
|
+
|
|
530
|
+
You delegate tasks to your team:
|
|
531
|
+
- Vulnerability Hunter: Initial scanning and detection
|
|
532
|
+
- Risk Assessor: Severity scoring and impact analysis
|
|
533
|
+
- Remediation Expert: Fix strategies and code samples
|
|
534
|
+
- Compliance Mapper: Regulatory and standards mapping
|
|
535
|
+
|
|
536
|
+
Always think strategically about the overall security posture."""
|
|
537
|
+
|
|
538
|
+
self._agents["lead"] = self._factory.create_agent(
|
|
539
|
+
name="security_lead",
|
|
540
|
+
role="coordinator",
|
|
541
|
+
description="Senior security architect who orchestrates the security audit team",
|
|
542
|
+
system_prompt=self._get_system_prompt("security_lead", lead_fallback),
|
|
543
|
+
model_tier=self.config.lead_tier,
|
|
544
|
+
memory_graph_enabled=self.config.memory_graph_enabled,
|
|
545
|
+
memory_graph_path=self.config.memory_graph_path,
|
|
546
|
+
resilience_enabled=self.config.resilience_enabled,
|
|
547
|
+
)
|
|
548
|
+
|
|
549
|
+
# 2. Vulnerability Hunter (Security Analyst)
|
|
550
|
+
hunter_fallback = """You are the Vulnerability Hunter, an expert security analyst.
|
|
551
|
+
|
|
552
|
+
Your focus areas:
|
|
553
|
+
1. OWASP Top 10 vulnerabilities
|
|
554
|
+
2. Injection attacks (SQL, NoSQL, OS command, LDAP)
|
|
555
|
+
3. Cross-Site Scripting (XSS) - stored, reflected, DOM
|
|
556
|
+
4. Authentication and session management flaws
|
|
557
|
+
5. Sensitive data exposure
|
|
558
|
+
6. Security misconfigurations
|
|
559
|
+
7. Insecure deserialization
|
|
560
|
+
8. Known vulnerable components
|
|
561
|
+
|
|
562
|
+
For each finding, provide:
|
|
563
|
+
- Clear description of the vulnerability
|
|
564
|
+
- Exact file and line number
|
|
565
|
+
- Code snippet showing the issue
|
|
566
|
+
- Confidence level (0.0-1.0)
|
|
567
|
+
|
|
568
|
+
Be thorough but avoid false positives. When uncertain, note the confidence level."""
|
|
569
|
+
|
|
570
|
+
self._agents["hunter"] = self._factory.create_agent(
|
|
571
|
+
name="vulnerability_hunter",
|
|
572
|
+
role="security",
|
|
573
|
+
description="Expert at finding OWASP Top 10 and common vulnerabilities",
|
|
574
|
+
system_prompt=self._get_system_prompt("vulnerability_hunter", hunter_fallback),
|
|
575
|
+
model_tier=self.config.hunter_tier,
|
|
576
|
+
memory_graph_enabled=self.config.memory_graph_enabled,
|
|
577
|
+
memory_graph_path=self.config.memory_graph_path,
|
|
578
|
+
)
|
|
579
|
+
|
|
580
|
+
# 3. Risk Assessor (Risk Analyst)
|
|
581
|
+
assessor_fallback = """You are the Risk Assessor, a security risk analyst.
|
|
582
|
+
|
|
583
|
+
Your methodology:
|
|
584
|
+
1. Apply CVSS v3.1 scoring methodology
|
|
585
|
+
2. Consider attack vector (Network, Adjacent, Local, Physical)
|
|
586
|
+
3. Assess attack complexity (Low, High)
|
|
587
|
+
4. Evaluate privileges required (None, Low, High)
|
|
588
|
+
5. Determine user interaction requirements
|
|
589
|
+
6. Calculate impact on Confidentiality, Integrity, Availability
|
|
590
|
+
|
|
591
|
+
For each vulnerability:
|
|
592
|
+
- Assign CVSS base score (0.0-10.0)
|
|
593
|
+
- Map to severity level (Critical: 9.0-10.0, High: 7.0-8.9, Medium: 4.0-6.9, Low: 0.1-3.9)
|
|
594
|
+
- Assess blast radius (single component, service, system-wide)
|
|
595
|
+
- Evaluate exploitability (known exploits, proof of concept, theoretical)
|
|
596
|
+
- Consider business context impact
|
|
597
|
+
|
|
598
|
+
Be precise and consistent in your scoring methodology."""
|
|
599
|
+
|
|
600
|
+
self._agents["assessor"] = self._factory.create_agent(
|
|
601
|
+
name="risk_assessor",
|
|
602
|
+
role="analyst",
|
|
603
|
+
description="Scores vulnerability severity and assesses blast radius",
|
|
604
|
+
system_prompt=self._get_system_prompt("risk_assessor", assessor_fallback),
|
|
605
|
+
model_tier=self.config.assessor_tier,
|
|
606
|
+
memory_graph_enabled=self.config.memory_graph_enabled,
|
|
607
|
+
memory_graph_path=self.config.memory_graph_path,
|
|
608
|
+
)
|
|
609
|
+
|
|
610
|
+
# 4. Remediation Expert (Security Engineer)
|
|
611
|
+
remediation_fallback = """You are the Remediation Expert, a senior security engineer.
|
|
612
|
+
|
|
613
|
+
For each vulnerability, provide:
|
|
614
|
+
|
|
615
|
+
1. **Immediate Fix**
|
|
616
|
+
- Specific code changes required
|
|
617
|
+
- Before/after code examples
|
|
618
|
+
- Step-by-step implementation guide
|
|
619
|
+
|
|
620
|
+
2. **Defense in Depth**
|
|
621
|
+
- Additional protective measures
|
|
622
|
+
- Monitoring and alerting recommendations
|
|
623
|
+
- Related hardening suggestions
|
|
624
|
+
|
|
625
|
+
3. **Effort Estimation**
|
|
626
|
+
- Time to implement (hours/days)
|
|
627
|
+
- Required expertise level
|
|
628
|
+
- Dependencies or prerequisites
|
|
629
|
+
|
|
630
|
+
4. **Verification**
|
|
631
|
+
- How to test the fix
|
|
632
|
+
- Regression test suggestions
|
|
633
|
+
- Security test cases
|
|
634
|
+
|
|
635
|
+
Prioritize fixes by:
|
|
636
|
+
- Severity × Exploitability × Effort
|
|
637
|
+
- Quick wins (high impact, low effort) first
|
|
638
|
+
- Group related fixes for efficiency"""
|
|
639
|
+
|
|
640
|
+
self._agents["remediation"] = self._factory.create_agent(
|
|
641
|
+
name="remediation_expert",
|
|
642
|
+
role="debugger",
|
|
643
|
+
description="Generates fix strategies with code examples",
|
|
644
|
+
system_prompt=self._get_system_prompt("remediation_expert", remediation_fallback),
|
|
645
|
+
model_tier=self.config.remediation_tier,
|
|
646
|
+
memory_graph_enabled=self.config.memory_graph_enabled,
|
|
647
|
+
memory_graph_path=self.config.memory_graph_path,
|
|
648
|
+
)
|
|
649
|
+
|
|
650
|
+
# 5. Compliance Mapper (Compliance Officer)
|
|
651
|
+
compliance_fallback = """You are the Compliance Mapper, a security compliance specialist.
|
|
652
|
+
|
|
653
|
+
Your responsibilities:
|
|
654
|
+
|
|
655
|
+
1. **CWE Mapping**
|
|
656
|
+
- Map each finding to relevant CWE IDs
|
|
657
|
+
- Provide CWE category and description
|
|
658
|
+
- Link to mitre.org references
|
|
659
|
+
|
|
660
|
+
2. **CVE Correlation**
|
|
661
|
+
- Check if vulnerability matches known CVEs
|
|
662
|
+
- Note CVE IDs when applicable
|
|
663
|
+
- Reference NVD entries
|
|
664
|
+
|
|
665
|
+
3. **OWASP Classification**
|
|
666
|
+
- Map to OWASP Top 10 categories
|
|
667
|
+
- Reference OWASP testing guides
|
|
668
|
+
- Note ASVS requirements
|
|
669
|
+
|
|
670
|
+
4. **Compliance Impact**
|
|
671
|
+
- PCI-DSS requirements affected
|
|
672
|
+
- HIPAA considerations (if healthcare)
|
|
673
|
+
- GDPR implications (if personal data)
|
|
674
|
+
- SOC2 control mappings
|
|
675
|
+
|
|
676
|
+
5. **Reporting Format**
|
|
677
|
+
- Structured output for compliance reports
|
|
678
|
+
- Evidence gathering suggestions
|
|
679
|
+
- Audit trail recommendations
|
|
680
|
+
|
|
681
|
+
Be precise with ID references. Verify CWE/CVE mappings are accurate."""
|
|
682
|
+
|
|
683
|
+
self._agents["compliance"] = self._factory.create_agent(
|
|
684
|
+
name="compliance_mapper",
|
|
685
|
+
role="analyst",
|
|
686
|
+
description="Maps findings to CWE, CVE, and compliance standards",
|
|
687
|
+
system_prompt=self._get_system_prompt("compliance_mapper", compliance_fallback),
|
|
688
|
+
model_tier=self.config.compliance_tier,
|
|
689
|
+
memory_graph_enabled=self.config.memory_graph_enabled,
|
|
690
|
+
memory_graph_path=self.config.memory_graph_path,
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
async def _create_workflow(self) -> None:
|
|
694
|
+
"""Create hierarchical workflow with Security Lead as manager."""
|
|
695
|
+
agents = list(self._agents.values())
|
|
696
|
+
|
|
697
|
+
self._workflow = self._factory.create_workflow(
|
|
698
|
+
name="security_audit_workflow",
|
|
699
|
+
agents=agents,
|
|
700
|
+
mode="hierarchical", # Security Lead delegates to others
|
|
701
|
+
description="Comprehensive security audit with coordinated analysis",
|
|
702
|
+
)
|
|
703
|
+
|
|
704
|
+
async def audit(
|
|
705
|
+
self,
|
|
706
|
+
target: str,
|
|
707
|
+
context: dict | None = None,
|
|
708
|
+
) -> SecurityReport:
|
|
709
|
+
"""Perform a comprehensive security audit.
|
|
710
|
+
|
|
711
|
+
Args:
|
|
712
|
+
target: Path to codebase or repository URL
|
|
713
|
+
context: Optional context (previous findings, focus areas, etc.)
|
|
714
|
+
|
|
715
|
+
Returns:
|
|
716
|
+
SecurityReport with all findings and recommendations
|
|
717
|
+
|
|
718
|
+
"""
|
|
719
|
+
import time
|
|
720
|
+
|
|
721
|
+
start_time = time.time()
|
|
722
|
+
|
|
723
|
+
# Initialize if needed
|
|
724
|
+
await self._initialize()
|
|
725
|
+
|
|
726
|
+
context = context or {}
|
|
727
|
+
findings: list[SecurityFinding] = []
|
|
728
|
+
memory_hits = 0
|
|
729
|
+
|
|
730
|
+
# Check Memory Graph for similar past findings
|
|
731
|
+
if self._graph and self.config.memory_graph_enabled:
|
|
732
|
+
try:
|
|
733
|
+
similar = self._graph.find_similar(
|
|
734
|
+
{"name": f"security_audit:{target}", "description": target},
|
|
735
|
+
threshold=0.4,
|
|
736
|
+
limit=10,
|
|
737
|
+
)
|
|
738
|
+
if similar:
|
|
739
|
+
memory_hits = len(similar)
|
|
740
|
+
context["similar_audits"] = [
|
|
741
|
+
{
|
|
742
|
+
"name": node.name,
|
|
743
|
+
"findings_count": node.metadata.get("findings_count", 0),
|
|
744
|
+
"risk_score": node.metadata.get("risk_score", 0),
|
|
745
|
+
}
|
|
746
|
+
for node, score in similar
|
|
747
|
+
]
|
|
748
|
+
logger.info(f"Found {memory_hits} similar past audits in Memory Graph")
|
|
749
|
+
except Exception as e:
|
|
750
|
+
logger.warning(f"Error querying Memory Graph: {e}")
|
|
751
|
+
|
|
752
|
+
# Build audit task for the crew
|
|
753
|
+
audit_task = self._build_audit_task(target, context)
|
|
754
|
+
|
|
755
|
+
# Execute the workflow
|
|
756
|
+
try:
|
|
757
|
+
result = await self._workflow.run(audit_task, initial_state=context)
|
|
758
|
+
|
|
759
|
+
# Parse findings from result
|
|
760
|
+
findings = self._parse_findings(result)
|
|
761
|
+
|
|
762
|
+
except Exception as e:
|
|
763
|
+
logger.error(f"Security audit failed: {e}")
|
|
764
|
+
# Return partial report with error
|
|
765
|
+
return SecurityReport(
|
|
766
|
+
target=target,
|
|
767
|
+
findings=findings,
|
|
768
|
+
summary=f"Audit failed with error: {e}",
|
|
769
|
+
audit_duration_seconds=time.time() - start_time,
|
|
770
|
+
agents_used=list(self._agents.keys()),
|
|
771
|
+
memory_graph_hits=memory_hits,
|
|
772
|
+
metadata={"error": str(e)},
|
|
773
|
+
)
|
|
774
|
+
|
|
775
|
+
# Build the report
|
|
776
|
+
duration = time.time() - start_time
|
|
777
|
+
report = SecurityReport(
|
|
778
|
+
target=target,
|
|
779
|
+
findings=findings,
|
|
780
|
+
summary=self._generate_summary(findings),
|
|
781
|
+
audit_duration_seconds=duration,
|
|
782
|
+
agents_used=list(self._agents.keys()),
|
|
783
|
+
memory_graph_hits=memory_hits,
|
|
784
|
+
metadata={
|
|
785
|
+
"scan_depth": self.config.scan_depth,
|
|
786
|
+
"framework": str(self._factory.framework.value),
|
|
787
|
+
},
|
|
788
|
+
)
|
|
789
|
+
|
|
790
|
+
# Store findings in Memory Graph
|
|
791
|
+
if self._graph and self.config.memory_graph_enabled and findings:
|
|
792
|
+
try:
|
|
793
|
+
self._graph.add_finding(
|
|
794
|
+
"security_audit_crew",
|
|
795
|
+
{
|
|
796
|
+
"type": "security_audit",
|
|
797
|
+
"name": f"audit:{target}",
|
|
798
|
+
"description": report.summary,
|
|
799
|
+
"findings_count": len(findings),
|
|
800
|
+
"risk_score": report.risk_score,
|
|
801
|
+
"critical_count": len(report.critical_findings),
|
|
802
|
+
},
|
|
803
|
+
)
|
|
804
|
+
self._graph._save()
|
|
805
|
+
except Exception as e:
|
|
806
|
+
logger.warning(f"Error storing audit in Memory Graph: {e}")
|
|
807
|
+
|
|
808
|
+
return report
|
|
809
|
+
|
|
810
|
+
def _build_audit_task(self, target: str, context: dict) -> str:
|
|
811
|
+
"""Build the audit task description for the crew."""
|
|
812
|
+
depth_instructions = {
|
|
813
|
+
"quick": "Focus on critical and high severity issues only. Skip detailed analysis.",
|
|
814
|
+
"standard": "Cover all OWASP Top 10 categories with moderate depth.",
|
|
815
|
+
"thorough": "Perform deep analysis including edge cases and complex attack chains.",
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
task = f"""Perform a comprehensive security audit of: {target}
|
|
819
|
+
|
|
820
|
+
Scan Depth: {self.config.scan_depth}
|
|
821
|
+
Instructions: {depth_instructions.get(self.config.scan_depth, depth_instructions["standard"])}
|
|
822
|
+
|
|
823
|
+
File Patterns to Include: {", ".join(self.config.include_patterns)}
|
|
824
|
+
File Patterns to Exclude: {", ".join(self.config.exclude_patterns)}
|
|
825
|
+
|
|
826
|
+
Workflow:
|
|
827
|
+
1. Security Lead coordinates the overall audit strategy
|
|
828
|
+
2. Vulnerability Hunter scans for security issues
|
|
829
|
+
3. Risk Assessor scores each finding by severity
|
|
830
|
+
4. Remediation Expert provides fix strategies
|
|
831
|
+
5. Compliance Mapper adds CWE/CVE references
|
|
832
|
+
|
|
833
|
+
For each finding, provide:
|
|
834
|
+
- Title and description
|
|
835
|
+
- Severity (critical/high/medium/low/info)
|
|
836
|
+
- Category (OWASP classification)
|
|
837
|
+
- File path and line number
|
|
838
|
+
- Code snippet
|
|
839
|
+
- Remediation steps
|
|
840
|
+
- CWE ID if applicable
|
|
841
|
+
- CVSS score
|
|
842
|
+
|
|
843
|
+
"""
|
|
844
|
+
if context.get("similar_audits"):
|
|
845
|
+
task += f"""
|
|
846
|
+
Previous Similar Audits Found: {len(context["similar_audits"])}
|
|
847
|
+
Consider patterns from past audits when analyzing.
|
|
848
|
+
"""
|
|
849
|
+
|
|
850
|
+
if context.get("focus_areas"):
|
|
851
|
+
task += f"""
|
|
852
|
+
Focus Areas Requested: {", ".join(context["focus_areas"])}
|
|
853
|
+
"""
|
|
854
|
+
|
|
855
|
+
return task
|
|
856
|
+
|
|
857
|
+
def _parse_findings(self, result: dict) -> list[SecurityFinding]:
|
|
858
|
+
"""Parse findings from workflow result."""
|
|
859
|
+
findings = []
|
|
860
|
+
|
|
861
|
+
output = result.get("output", "")
|
|
862
|
+
metadata = result.get("metadata", {})
|
|
863
|
+
|
|
864
|
+
# Check for structured findings in metadata
|
|
865
|
+
if "findings" in metadata:
|
|
866
|
+
for f in metadata["findings"]:
|
|
867
|
+
findings.append(self._dict_to_finding(f))
|
|
868
|
+
return findings
|
|
869
|
+
|
|
870
|
+
# Parse from text output (fallback)
|
|
871
|
+
# This is a simplified parser - in production, use structured output
|
|
872
|
+
findings = self._parse_text_findings(output)
|
|
873
|
+
|
|
874
|
+
return findings
|
|
875
|
+
|
|
876
|
+
def _dict_to_finding(self, data: dict) -> SecurityFinding:
|
|
877
|
+
"""Convert dictionary to SecurityFinding."""
|
|
878
|
+
return SecurityFinding(
|
|
879
|
+
title=data.get("title", "Untitled Finding"),
|
|
880
|
+
description=data.get("description", ""),
|
|
881
|
+
severity=Severity(data.get("severity", "medium")),
|
|
882
|
+
category=FindingCategory(data.get("category", "other")),
|
|
883
|
+
file_path=data.get("file_path"),
|
|
884
|
+
line_number=data.get("line_number"),
|
|
885
|
+
code_snippet=data.get("code_snippet"),
|
|
886
|
+
remediation=data.get("remediation"),
|
|
887
|
+
cwe_id=data.get("cwe_id"),
|
|
888
|
+
cvss_score=data.get("cvss_score"),
|
|
889
|
+
confidence=data.get("confidence", 1.0),
|
|
890
|
+
metadata=data.get("metadata", {}),
|
|
891
|
+
)
|
|
892
|
+
|
|
893
|
+
def _parse_text_findings(self, text: str) -> list[SecurityFinding]:
|
|
894
|
+
"""Parse findings from unstructured text output."""
|
|
895
|
+
findings = []
|
|
896
|
+
|
|
897
|
+
# Simple heuristic parsing - look for severity indicators
|
|
898
|
+
severity_keywords = {
|
|
899
|
+
Severity.CRITICAL: ["critical", "rce", "remote code execution"],
|
|
900
|
+
Severity.HIGH: ["high", "injection", "authentication bypass"],
|
|
901
|
+
Severity.MEDIUM: ["medium", "xss", "csrf"],
|
|
902
|
+
Severity.LOW: ["low", "information disclosure"],
|
|
903
|
+
Severity.INFO: ["info", "informational", "best practice"],
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
category_keywords = {
|
|
907
|
+
FindingCategory.INJECTION: ["sql injection", "command injection", "ldap"],
|
|
908
|
+
FindingCategory.XSS: ["xss", "cross-site scripting", "script injection"],
|
|
909
|
+
FindingCategory.BROKEN_AUTH: ["authentication", "session", "password"],
|
|
910
|
+
FindingCategory.SENSITIVE_DATA: ["sensitive data", "encryption", "plaintext"],
|
|
911
|
+
FindingCategory.MISCONFIGURATION: ["misconfiguration", "default", "exposed"],
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
# Split into potential findings (very basic)
|
|
915
|
+
lines = text.split("\n")
|
|
916
|
+
current_finding = None
|
|
917
|
+
|
|
918
|
+
for line in lines:
|
|
919
|
+
line_lower = line.lower().strip()
|
|
920
|
+
|
|
921
|
+
# Detect severity
|
|
922
|
+
detected_severity = Severity.MEDIUM
|
|
923
|
+
for sev, keywords in severity_keywords.items():
|
|
924
|
+
if any(kw in line_lower for kw in keywords):
|
|
925
|
+
detected_severity = sev
|
|
926
|
+
break
|
|
927
|
+
|
|
928
|
+
# Detect category
|
|
929
|
+
detected_category = FindingCategory.OTHER
|
|
930
|
+
for cat, keywords in category_keywords.items():
|
|
931
|
+
if any(kw in line_lower for kw in keywords):
|
|
932
|
+
detected_category = cat
|
|
933
|
+
break
|
|
934
|
+
|
|
935
|
+
# Simple finding detection
|
|
936
|
+
if any(
|
|
937
|
+
indicator in line_lower
|
|
938
|
+
for indicator in ["vulnerability", "issue", "finding", "detected"]
|
|
939
|
+
):
|
|
940
|
+
if current_finding:
|
|
941
|
+
findings.append(current_finding)
|
|
942
|
+
|
|
943
|
+
current_finding = SecurityFinding(
|
|
944
|
+
title=line[:100].strip(),
|
|
945
|
+
description=line,
|
|
946
|
+
severity=detected_severity,
|
|
947
|
+
category=detected_category,
|
|
948
|
+
)
|
|
949
|
+
|
|
950
|
+
if current_finding:
|
|
951
|
+
findings.append(current_finding)
|
|
952
|
+
|
|
953
|
+
return findings
|
|
954
|
+
|
|
955
|
+
def _generate_summary(self, findings: list[SecurityFinding]) -> str:
|
|
956
|
+
"""Generate executive summary of findings."""
|
|
957
|
+
if not findings:
|
|
958
|
+
return "No security issues were identified during the audit."
|
|
959
|
+
|
|
960
|
+
critical = sum(1 for f in findings if f.severity == Severity.CRITICAL)
|
|
961
|
+
high = sum(1 for f in findings if f.severity == Severity.HIGH)
|
|
962
|
+
medium = sum(1 for f in findings if f.severity == Severity.MEDIUM)
|
|
963
|
+
low = sum(1 for f in findings if f.severity == Severity.LOW)
|
|
964
|
+
|
|
965
|
+
summary_parts = [f"Security audit identified {len(findings)} findings:"]
|
|
966
|
+
|
|
967
|
+
if critical > 0:
|
|
968
|
+
summary_parts.append(f" - {critical} CRITICAL (immediate action required)")
|
|
969
|
+
if high > 0:
|
|
970
|
+
summary_parts.append(f" - {high} HIGH (address within 7 days)")
|
|
971
|
+
if medium > 0:
|
|
972
|
+
summary_parts.append(f" - {medium} MEDIUM (address within 30 days)")
|
|
973
|
+
if low > 0:
|
|
974
|
+
summary_parts.append(f" - {low} LOW (address in next sprint)")
|
|
975
|
+
|
|
976
|
+
# Add top categories
|
|
977
|
+
by_category: dict[str, int] = {}
|
|
978
|
+
for f in findings:
|
|
979
|
+
cat = f.category.value
|
|
980
|
+
by_category[cat] = by_category.get(cat, 0) + 1
|
|
981
|
+
|
|
982
|
+
if by_category:
|
|
983
|
+
top_cats = sorted(by_category.items(), key=lambda x: x[1], reverse=True)[:3]
|
|
984
|
+
summary_parts.append("\nTop vulnerability categories:")
|
|
985
|
+
for cat, count in top_cats:
|
|
986
|
+
summary_parts.append(f" - {cat}: {count}")
|
|
987
|
+
|
|
988
|
+
return "\n".join(summary_parts)
|
|
989
|
+
|
|
990
|
+
@property
|
|
991
|
+
def agents(self) -> dict[str, Any]:
|
|
992
|
+
"""Get the crew's agents."""
|
|
993
|
+
return self._agents
|
|
994
|
+
|
|
995
|
+
@property
|
|
996
|
+
def is_initialized(self) -> bool:
|
|
997
|
+
"""Check if crew is initialized."""
|
|
998
|
+
return self._initialized
|
|
999
|
+
|
|
1000
|
+
async def get_agent_stats(self) -> dict:
|
|
1001
|
+
"""Get statistics about crew agents."""
|
|
1002
|
+
await self._initialize()
|
|
1003
|
+
|
|
1004
|
+
agents_dict: dict = {}
|
|
1005
|
+
stats: dict = {
|
|
1006
|
+
"agent_count": len(self._agents),
|
|
1007
|
+
"agents": agents_dict,
|
|
1008
|
+
"framework": self._factory.framework.value if self._factory else "unknown",
|
|
1009
|
+
"memory_graph_enabled": self.config.memory_graph_enabled,
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
for name, agent in self._agents.items():
|
|
1013
|
+
agents_dict[name] = {
|
|
1014
|
+
"role": agent.config.role if hasattr(agent, "config") else "unknown",
|
|
1015
|
+
"model_tier": getattr(agent.config, "model_tier", "unknown"),
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
return stats
|