================================================================================
CODE COMPLEXITY ANALYSIS REPORT
LionAGI QE Fleet - Recent Changes Analysis
================================================================================

OVERALL COMPLEXITY SCORE: 15.3/100
  (100 = low complexity, excellent maintainability)

Summary Statistics:
  Files Analyzed: 7
  Total Lines: 4,018
  Total Methods/Functions: 66
  Average Cyclomatic Complexity: 16.94
  Average Maintainability Index: 57.99
  Quality Grade: F (Critical)

FILES RANKED BY COMPLEXITY:
--------------------------------------------------------------------------------
1. hooks.py                                 LOC:  532 | Methods:  13 | Avg Complexity: 31.00 | MI: 58.58
2. base_agent.py                            LOC:  573 | Methods:  19 | Avg Complexity: 30.00 | MI: 57.61
3. orchestrator.py                          LOC:  666 | Methods:  13 | Avg Complexity: 21.00 | MI: 55.14
4. code_analyzer.py                         LOC:  306 | Methods:   5 | Avg Complexity: 16.67 | MI: 67.24
5. test_generator.py                        LOC:  745 | Methods:   5 | Avg Complexity: 11.00 | MI: 52.02
6. test_executor.py                         LOC:  269 | Methods:   4 | Avg Complexity:  7.00 | MI: 71.55
7. flaky_test_hunter.py                     LOC:  927 | Methods:   7 | Avg Complexity:  1.90 | MI: 43.81

CRITICAL ISSUES (Require Immediate Refactoring):
--------------------------------------------------------------------------------
  [MEDIUM] orchestrator.py::QEOrchestrator::execute_fan_out_fan_in (line 225): Method length = 67 lines (threshold: 50)
  [MEDIUM] orchestrator.py::QEOrchestrator::execute_parallel_expansion (line 329): Long parameter list = 7 params (threshold: 5)
  [MEDIUM] orchestrator.py::QEOrchestrator::execute_parallel_fan_out_fan_in (line 436): Method length = 90 lines (threshold: 50)
  [MEDIUM] orchestrator.py::QEOrchestrator::execute_conditional_workflow (line 527): Long parameter list = 6 params (threshold: 5)
  [MEDIUM] base_agent.py::BaseQEAgent::__init__ (line 44): Long parameter list = 6 params (threshold: 5)
  [MEDIUM] hooks.py::QEHooks::get_metrics (line 328): Method length = 60 lines (threshold: 50)
  [MEDIUM] hooks.py::QEHooks::export_metrics (line 408): Method length = 51 lines (threshold: 50)
  [MEDIUM] test_executor.py::TestExecutorAgent::execute (line 70): Method length = 65 lines (threshold: 50)
  [MEDIUM] flaky_test_hunter.py::run_test_multiple_times (line 618): Method length = 87 lines (threshold: 50)
  [MEDIUM] test_generator.py::TestGeneratorAgent::execute (line 111): Method length = 66 lines (threshold: 50)
  [MEDIUM] test_generator.py::TestGeneratorAgent::_extract_test_from_chunks (line 383): Method length = 60 lines (threshold: 50)
  [MEDIUM] code_analyzer.py::ASTParserTool::analyze_control_flow (line 167): Method length = 54 lines (threshold: 50)
  [MEDIUM] code_analyzer.py::ASTParserTool::detect_edge_cases (line 223): Method length = 78 lines (threshold: 50)
  [HIGH] hooks.py::QEHooks::post_invocation_hook (line 136): Cyclomatic complexity = 11 (threshold: 10)
  [HIGH] test_executor.py::TestExecutorAgent::execute_tests_parallel (line 136): Cyclomatic complexity = 11 (threshold: 10)
  [HIGH] test_generator.py::TestGeneratorAgent::generate_tests_streaming (line 178): Deep nesting = 5 levels (threshold: 4)
  [HIGH] test_generator.py::TestGeneratorAgent::execute_with_reasoning (line 444): Deep nesting = 7 levels (threshold: 4)
  [HIGH] code_analyzer.py::CodeAnalyzerTool::analyze_code (line 33): Deep nesting = 6 levels (threshold: 4)
  [HIGH] code_analyzer.py::ASTParserTool::detect_edge_cases (line 223): Cyclomatic complexity = 14 (threshold: 10)
  [CRITICAL] orchestrator.py::QEOrchestrator::execute_parallel_expansion (line 329): Method length = 106 lines (threshold: 100)
  [CRITICAL] orchestrator.py::QEOrchestrator::execute_conditional_workflow (line 527): Method length = 118 lines (threshold: 100)
  [CRITICAL] base_agent.py::BaseQEAgent::safe_operate (line 355): Method length = 113 lines (threshold: 100)
  [CRITICAL] base_agent.py::BaseQEAgent::safe_parse_response (line 469): Method length = 104 lines (threshold: 100)
  [CRITICAL] hooks.py::QEHooks::post_invocation_hook (line 136): Method length = 111 lines (threshold: 100)
  [CRITICAL] test_executor.py::TestExecutorAgent::execute_tests_parallel (line 136): Method length = 133 lines (threshold: 100)
  [CRITICAL] flaky_test_hunter.py::execute (line 807): Method length = 120 lines (threshold: 100)
  [CRITICAL] flaky_test_hunter.py::FlakyTestHunterAgent::execute (line 447): Method length = 139 lines (threshold: 100)
  [CRITICAL] flaky_test_hunter.py::FlakyTestHunterAgent::detect_flaky_tests (line 587): Method length = 174 lines (threshold: 100)
  [CRITICAL] test_generator.py::TestGeneratorAgent::generate_tests_streaming (line 178): Cyclomatic complexity = 16 (threshold: 10)
  [CRITICAL] test_generator.py::TestGeneratorAgent::generate_tests_streaming (line 178): Cognitive complexity = 26 (threshold: 15)
  [CRITICAL] test_generator.py::TestGeneratorAgent::generate_tests_streaming (line 178): Method length = 204 lines (threshold: 100)
  [CRITICAL] test_generator.py::TestGeneratorAgent::execute_with_reasoning (line 444): Cyclomatic complexity = 28 (threshold: 10)
  [CRITICAL] test_generator.py::TestGeneratorAgent::execute_with_reasoning (line 444): Cognitive complexity = 47 (threshold: 15)
  [CRITICAL] test_generator.py::TestGeneratorAgent::execute_with_reasoning (line 444): Method length = 301 lines (threshold: 100)
  [CRITICAL] code_analyzer.py::CodeAnalyzerTool::analyze_code (line 33): Cyclomatic complexity = 24 (threshold: 10)
  [CRITICAL] code_analyzer.py::CodeAnalyzerTool::analyze_code (line 33): Cognitive complexity = 40 (threshold: 15)
  [CRITICAL] code_analyzer.py::CodeAnalyzerTool::analyze_code (line 33): Method length = 116 lines (threshold: 100)
  [CRITICAL] code_analyzer.py::ASTParserTool::detect_edge_cases (line 223): Cognitive complexity = 26 (threshold: 15)

DETAILED METRICS BY FILE:
================================================================================

File: src/lionagi_qe/core/orchestrator.py
  Lines: 666
  Maintainability Index: 55.14
  Total Complexity: 42
  Average Complexity: 21.00

  Top Complex Methods:
    - execute_conditional_workflow (line 527): CC=8, CogC=11, Lines=118, Nesting=3
    - execute_parallel_fan_out_fan_in (line 436): CC=8, CogC=7, Lines=90, Nesting=2
    - execute_parallel_expansion (line 329): CC=5, CogC=3, Lines=106, Nesting=1
    - execute_pipeline (line 123): CC=3, CogC=3, Lines=50, Nesting=2
    - execute_fan_out_fan_in (line 225): CC=4, CogC=1, Lines=67, Nesting=1

File: src/lionagi_qe/core/base_agent.py
  Lines: 573
  Maintainability Index: 57.61
  Total Complexity: 30
  Average Complexity: 30.00

  Top Complex Methods:
    - safe_parse_response (line 469): CC=6, CogC=8, Lines=104, Nesting=3
    - safe_operate (line 355): CC=4, CogC=5, Lines=113, Nesting=2
    - __init__ (line 44): CC=2, CogC=1, Lines=40, Nesting=0
    - get_memory (line 138): CC=2, CogC=1, Lines=18, Nesting=1
    - post_execution_hook (line 225): CC=2, CogC=1, Lines=25, Nesting=1

File: src/lionagi_qe/core/hooks.py
  Lines: 532
  Maintainability Index: 58.58
  Total Complexity: 31
  Average Complexity: 31.00

  Top Complex Methods:
    - post_invocation_hook (line 136): CC=11, CogC=10, Lines=111, Nesting=1
    - export_metrics (line 408): CC=4, CogC=6, Lines=51, Nesting=3
    - _trigger_cost_alert (line 295): CC=3, CogC=2, Lines=16, Nesting=1
    - pre_invocation_hook (line 86): CC=2, CogC=1, Lines=49, Nesting=1
    - _estimate_cost (line 248): CC=2, CogC=1, Lines=46, Nesting=1

File: src/lionagi_qe/agents/test_executor.py
  Lines: 269
  Maintainability Index: 71.55
  Total Complexity: 21
  Average Complexity: 7.00

  Top Complex Methods:
    - execute_tests_parallel (line 136): CC=11, CogC=8, Lines=133, Nesting=4
    - run_single_test (line 167): CC=6, CogC=8, Lines=49, Nesting=4
    - execute (line 70): CC=3, CogC=2, Lines=65, Nesting=1
    - get_system_prompt (line 39): CC=1, CogC=0, Lines=30, Nesting=0

File: src/lionagi_qe/agents/flaky_test_hunter.py
  Lines: 927
  Maintainability Index: 43.81
  Total Complexity: 40
  Average Complexity: 1.90

  Top Complex Methods:
    - detect_flaky_tests (line 587): CC=10, CogC=8, Lines=174, Nesting=4
    - _identify_pattern (line 762): CC=8, CogC=11, Lines=39, Nesting=3
    - run_test_multiple_times (line 618): CC=8, CogC=8, Lines=87, Nesting=4
    - execute_test_once (line 621): CC=6, CogC=8, Lines=47, Nesting=4
    - execute (line 447): CC=6, CogC=7, Lines=139, Nesting=3

File: src/lionagi_qe/agents/test_generator.py
  Lines: 745
  Maintainability Index: 52.02
  Total Complexity: 55
  Average Complexity: 11.00

  Top Complex Methods:
    - execute_with_reasoning (line 444): CC=28, CogC=47, Lines=301, Nesting=7
    - generate_tests_streaming (line 178): CC=16, CogC=26, Lines=204, Nesting=5
    - _extract_test_from_chunks (line 383): CC=8, CogC=9, Lines=60, Nesting=3
    - execute (line 111): CC=2, CogC=1, Lines=66, Nesting=1
    - get_system_prompt (line 81): CC=1, CogC=0, Lines=29, Nesting=0

File: src/lionagi_qe/tools/code_analyzer.py
  Lines: 306
  Maintainability Index: 67.24
  Total Complexity: 50
  Average Complexity: 16.67

  Top Complex Methods:
    - analyze_code (line 33): CC=24, CogC=40, Lines=116, Nesting=6
    - detect_edge_cases (line 223): CC=14, CogC=26, Lines=78, Nesting=4
    - analyze_control_flow (line 167): CC=10, CogC=10, Lines=54, Nesting=2
    - get_callable (line 151): CC=1, CogC=0, Lines=3, Nesting=0
    - get_callable (line 303): CC=1, CogC=0, Lines=3, Nesting=0


3. General: High average complexity across codebase
   Recommendation: Apply Extract Method pattern to break down complex logic

CODE QUALITY TRENDS:
--------------------------------------------------------------------------------
  Total Methods: 66
  Complex Methods (CC > 10): 6 (9.1%)
  Very Complex Methods (CC > 15): 3 (4.5%)

  Complexity Distribution:
    Critical (>15)      : ##                               3 (  4.5%)
    High (11-15)        : ##                               3 (  4.5%)
    Low (1-5)           : #####################################  49 ( 74.2%)
    Medium (6-10)       : ########                        11 ( 16.7%)