|
| 1 | +# Deep Codebase Metrics Analysis |
| 2 | + |
| 3 | +**Generated:** 2025-11-28 |
| 4 | +**Repository:** code-assistant-manager |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## 📊 Executive Summary |
| 9 | + |
| 10 | +| Metric | Value | Health | |
| 11 | +|--------|-------|--------| |
| 12 | +| Total Source Files | 96 | ✅ Good | |
| 13 | +| Total Lines of Code | 24,046 | ✅ Manageable | |
| 14 | +| Total Functions | 949 | ✅ Good | |
| 15 | +| Total Classes | 143 | ✅ Good | |
| 16 | +| Docstring Coverage | 86% | ✅ Excellent | |
| 17 | +| Type Hint Coverage | 89% | ✅ Excellent | |
| 18 | +| Simple Functions (CC ≤ 5) | 77% | ✅ Excellent | |
| 19 | +| Complex Functions (CC > 15) | 2% (19 functions) | ⚠️ Needs Attention | |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## 📏 File Size Distribution |
| 24 | + |
| 25 | +``` |
| 26 | +File Size Count Distribution |
| 27 | +──────────────────────────────────────────── |
| 28 | +Small (<100 lines) 34 ████████████████████ |
| 29 | +Medium (100-300 lines) 28 ████████████████ |
| 30 | +Large (300-500 lines) 21 ████████████ |
| 31 | +X-Large (>500 lines) 13 ███████ ⚠️ |
| 32 | +``` |
| 33 | + |
| 34 | +### X-Large Files (>500 lines) - Refactoring Candidates |
| 35 | + |
| 36 | +| File | Lines | Priority | |
| 37 | +|------|------:|----------| |
| 38 | +| `cli/commands.py` | 1,338 | 🔴 Critical | |
| 39 | +| `mcp/base_client.py` | 1,188 | 🔴 Critical | |
| 40 | +| `cli/plugin_commands.py` | 956 | 🟠 High | |
| 41 | +| `cli/prompts_commands.py` | 842 | 🟠 High | |
| 42 | +| `menu/base.py` | 744 | 🟡 Medium | |
| 43 | +| `config.py` | 608 | 🟡 Medium | |
| 44 | +| `endpoints.py` | 576 | 🟡 Medium | |
| 45 | +| `tools/base.py` | 564 | 🟡 Medium | |
| 46 | +| `tools/crush.py` | 551 | 🟡 Medium | |
| 47 | +| `plugins/manager.py` | 547 | 🟡 Medium | |
| 48 | +| `prompts/manager.py` | 540 | 🟡 Medium | |
| 49 | +| `skills/manager.py` | 525 | 🟡 Medium | |
| 50 | +| `cli/skills_commands.py` | 524 | 🟡 Medium | |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## 🔄 Cyclomatic Complexity Distribution |
| 55 | + |
| 56 | +``` |
| 57 | +Complexity Level Count Percentage |
| 58 | +───────────────────────────────────────────── |
| 59 | +Simple (1-5) 731 77% ███████████████████████ |
| 60 | +Moderate (6-10) 172 18% █████ |
| 61 | +Complex (11-15) 27 3% █ |
| 62 | +Very Complex (>15) 19 2% ⚠️ |
| 63 | +``` |
| 64 | + |
| 65 | +### Very High Complexity Functions (CC > 15) |
| 66 | + |
| 67 | +These functions are the most difficult to test and maintain: |
| 68 | + |
| 69 | +| CC | File | Function | Line | Root Cause | |
| 70 | +|---:|------|----------|-----:|------------| |
| 71 | +| 68 | `cli/upgrade.py` | `handle_upgrade_command()` | 12 | Multiple upgrade paths | |
| 72 | +| 51 | `cli/doctor.py` | `run_doctor_checks()` | 16 | Many diagnostic checks | |
| 73 | +| 32 | `cli/plugin_commands.py` | `browse_marketplace()` | 620 | Mixed concerns | |
| 74 | +| 30 | `mcp/claude.py` | `list_servers()` | 274 | Complex config parsing | |
| 75 | +| 25 | `config.py` | `validate_command()` | 384 | Large pattern lists | |
| 76 | +| 24 | `config.py` | `validate_config()` | 195 | Nested validation | |
| 77 | +| 22 | `mcp/copilot.py` | `list_servers()` | 241 | Config parsing | |
| 78 | +| 22 | `mcp/codebuddy.py` | `list_servers()` | 264 | Config parsing | |
| 79 | +| 20 | `mcp/server_commands.py` | `show()` | 111 | Display branching | |
| 80 | +| 18 | `cli/utils.py` | `legacy_main()` | 21 | Legacy code | |
| 81 | +| 18 | `mcp/base_client.py` | `_read_servers_from_configs()` | 423 | Multi-format parsing | |
| 82 | +| 17 | `plugins/base.py` | `_download_repo()` | 341 | Error handling | |
| 83 | +| 17 | `mcp/base_client.py` | `_read_servers_from_configs_legacy()` | 477 | Legacy support | |
| 84 | +| 17 | `skills/base.py` | `_download_repo()` | 179 | Error handling | |
| 85 | +| 17 | `agents/base.py` | `_download_repo()` | 223 | Error handling | |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## 📝 Code Quality Metrics |
| 90 | + |
| 91 | +### Documentation Coverage (86% - Excellent) |
| 92 | + |
| 93 | +``` |
| 94 | + With Docstrings Without Docstrings |
| 95 | +Functions: 820 (86%) 129 (14%) |
| 96 | + ████████████████████ ███ |
| 97 | +``` |
| 98 | + |
| 99 | +**Analysis:** The codebase has excellent documentation coverage. Most functions have descriptive docstrings, which significantly aids maintainability. |
| 100 | + |
| 101 | +### Type Hint Coverage (89% - Excellent) |
| 102 | + |
| 103 | +``` |
| 104 | + With Type Hints Without Type Hints |
| 105 | +Functions: 852 (89%) 97 (11%) |
| 106 | + ██████████████████████ ██ |
| 107 | +``` |
| 108 | + |
| 109 | +**Analysis:** Strong type hint adoption. This enables better IDE support, catch bugs early, and improves code readability. |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +## 📚 Dependency Analysis |
| 114 | + |
| 115 | +### Top Dependencies by Import Count |
| 116 | + |
| 117 | +| Dependency | Imports | Category | |
| 118 | +|------------|--------:|----------| |
| 119 | +| `pathlib` | 75 | Standard Library | |
| 120 | +| `typing` | 71 | Standard Library | |
| 121 | +| `code_assistant_manager` | 59 | Internal | |
| 122 | +| `json` | 51 | Standard Library | |
| 123 | +| `logging` | 32 | Standard Library | |
| 124 | +| `os` | 27 | Standard Library | |
| 125 | +| `typer` | 17 | CLI Framework | |
| 126 | +| `subprocess` | 14 | Standard Library | |
| 127 | +| `abc` | 10 | Standard Library | |
| 128 | +| `shutil` | 10 | Standard Library | |
| 129 | + |
| 130 | +### Dependency Health Assessment |
| 131 | + |
| 132 | +| Aspect | Status | Notes | |
| 133 | +|--------|--------|-------| |
| 134 | +| External Dependencies | ✅ Minimal | Few third-party deps (typer, requests, pydantic) | |
| 135 | +| Standard Library Usage | ✅ Good | Heavy use of built-in modules | |
| 136 | +| Internal Coupling | 🟡 Moderate | 59 internal imports - review for circular deps | |
| 137 | +| CLI Framework | ✅ Consistent | Typer used throughout | |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +## 🔗 Module Coupling Analysis |
| 142 | + |
| 143 | +### High-Traffic Modules (Most Imported) |
| 144 | + |
| 145 | +1. **`base` modules** (45 imports) - Good abstraction pattern |
| 146 | +2. **`models`** (10 imports) - Data model centralization |
| 147 | +3. **`base_client`** (13 imports) - MCP client base class |
| 148 | + |
| 149 | +### Potential Issues |
| 150 | + |
| 151 | +- **`cli/commands.py`** (1,338 lines) imports many modules - candidate for splitting |
| 152 | +- **`mcp/base_client.py`** (1,188 lines) - complex inheritance hierarchy |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +## 📈 Trend Indicators |
| 157 | + |
| 158 | +Based on git history and current metrics: |
| 159 | + |
| 160 | +### Positive Trends ✅ |
| 161 | +- Recent commits show complexity reduction efforts (`5ca0ed4`) |
| 162 | +- Test coverage is improving with dedicated test commits |
| 163 | +- New features follow modular patterns (agents, skills as packages) |
| 164 | + |
| 165 | +### Areas Needing Attention ⚠️ |
| 166 | +- Legacy upgrade/doctor functions have very high complexity |
| 167 | +- Several CLI modules exceed size limits |
| 168 | +- Some `list_servers()` implementations are duplicated across MCP clients |
| 169 | + |
| 170 | +--- |
| 171 | + |
| 172 | +## 🎯 Actionable Recommendations |
| 173 | + |
| 174 | +### Immediate (This Sprint) |
| 175 | + |
| 176 | +1. **Refactor `handle_upgrade_command()` (CC=68)** |
| 177 | + - Split into separate upgrade strategies per tool |
| 178 | + - Use strategy pattern |
| 179 | + |
| 180 | +2. **Refactor `run_doctor_checks()` (CC=51)** |
| 181 | + - Extract each check into a separate function |
| 182 | + - Use a check registry pattern |
| 183 | + |
| 184 | +3. **Split `cli/commands.py` (1,338 lines)** |
| 185 | + - Create `endpoint_commands.py` |
| 186 | + - Create `launch_commands.py` |
| 187 | + - Create `model_commands.py` |
| 188 | + |
| 189 | +### Short-Term (Next 2 Sprints) |
| 190 | + |
| 191 | +4. **Consolidate `list_servers()` implementations** |
| 192 | + - DRY violation across `claude.py`, `copilot.py`, `codebuddy.py` |
| 193 | + - Move common logic to `base_client.py` |
| 194 | + |
| 195 | +5. **Extract `_download_repo()` to shared module** |
| 196 | + - Identical implementations in `plugins/base.py`, `skills/base.py`, `agents/base.py` |
| 197 | + |
| 198 | +### Long-Term (Quarterly) |
| 199 | + |
| 200 | +6. **Consider splitting `mcp/base_client.py`** |
| 201 | + - Separate config reading from client operations |
| 202 | + - Create dedicated config parser module |
| 203 | + |
| 204 | +7. **Increase test coverage for complex functions** |
| 205 | + - Priority: All CC > 15 functions |
| 206 | + |
| 207 | +--- |
| 208 | + |
| 209 | +## 📊 Health Score Card |
| 210 | + |
| 211 | +| Category | Score | Grade | |
| 212 | +|----------|------:|-------| |
| 213 | +| File Organization | 75/100 | B | |
| 214 | +| Code Complexity | 70/100 | B- | |
| 215 | +| Documentation | 90/100 | A | |
| 216 | +| Type Safety | 90/100 | A | |
| 217 | +| Test Coverage | 65/100 | C+ | |
| 218 | +| Dependency Management | 85/100 | A- | |
| 219 | +| **Overall** | **79/100** | **B+** | |
| 220 | + |
| 221 | +--- |
| 222 | + |
| 223 | +## Appendix: Methodology |
| 224 | + |
| 225 | +### Cyclomatic Complexity Calculation |
| 226 | + |
| 227 | +CC is calculated by counting: |
| 228 | +- +1 for each `if`, `elif`, `while`, `for` |
| 229 | +- +1 for each `except` handler |
| 230 | +- +1 for each `with` statement |
| 231 | +- +1 for each `assert` |
| 232 | +- +1 for each boolean operator (`and`, `or`) |
| 233 | +- +1 for each comprehension |
| 234 | + |
| 235 | +### File Size Categories |
| 236 | + |
| 237 | +- **Small**: < 100 lines (ideal for most modules) |
| 238 | +- **Medium**: 100-300 lines (acceptable for complex modules) |
| 239 | +- **Large**: 300-500 lines (consider splitting) |
| 240 | +- **X-Large**: > 500 lines (should be split) |
| 241 | + |
| 242 | +### Health Score Formula |
| 243 | + |
| 244 | +``` |
| 245 | +Health = 100 - (max_complexity * 3) - (lines / 100 * 5) |
| 246 | +``` |
| 247 | + |
| 248 | +Where: |
| 249 | +- Files with CC > 10 are penalized heavily |
| 250 | +- Files > 500 lines are considered unhealthy |
0 commit comments