# Codebase Analysis Script\n\nScript to analyze the technology distribution in the provisioning codebase.\n\n## Usage\n\n### Basic Usage\n\n```\n# From provisioning directory (analyzes current directory)\ncd provisioning\nnu tools/analyze-codebase.nu\n\n# From project root, analyze provisioning\nnu provisioning/tools/analyze-codebase.nu --path provisioning\n\n# Analyze any path\nnu provisioning/tools/analyze-codebase.nu --path /absolute/path/to/directory\n```\n\n### Output Formats\n\n```\n# Table format (default) - colored, visual bars\nnu provisioning/tools/analyze-codebase.nu --format table\n\n# JSON format - for programmatic use\nnu provisioning/tools/analyze-codebase.nu --format json\n\n# Markdown format - for documentation\nnu provisioning/tools/analyze-codebase.nu --format markdown\n```\n\n### From provisioning directory\n\n```\ncd provisioning\nnu tools/analyze-codebase.nu\n```\n\n### Direct execution (if in PATH)\n\n```\n# Make it globally available (one time)\nln -sf "$(pwd)/provisioning/tools/analyze-codebase.nu" /usr/local/bin/analyze-codebase\n\n# Then run from anywhere\nanalyze-codebase\nanalyze-codebase --format json\nanalyze-codebase --format markdown > CODEBASE_STATS.md\n```\n\n## Output\n\nThe script analyzes:\n\n- **Nushell** (.nu files)\n- **KCL** (.k files)\n- **Rust** (.rs files)\n- **Templates** (.j2, .tera files)\n\nAcross these sections:\n\n- `core/` - CLI interface, core libraries\n- `extensions/` - Providers, taskservs, clusters\n- `platform/` - Rust services (orchestrator, control-center, etc.)\n- `templates/` - Template files\n- `kcl/` - KCL configuration schemas\n\n## Example Output\n\n### Table Format\n\n```\n📊 Analyzing Codebase: provisioning\n\n📋 Lines of Code by Section\n\n╭─────────────┬─────────┬────────────┬─────┬─────────┬─────┬──────────┬───────────┬───────────────┬───────────┬───────╮\n│ section     │ nushell │ nushell_pct│ kcl │ kcl_pct │ rust│ rust_pct │ templates │ templates_pct │ total     │       │\n├─────────────┼─────────┼────────────┼─────┼─────────┼─────┼──────────┼───────────┼───────────────┼───────────┼───────┤\n│ core        │   53843 │      99.87 │  71 │    0.13 │   0 │     0.00 │         0 │          0.00 │     53914 │       │\n│ extensions  │   10202 │      43.21 │3946 │   16.72 │   0 │     0.00 │      9456 │         40.05 │     23604 │       │\n│ platform    │    5759 │       0.19 │   0 │    0.00 │2992107│  99.81 │         0 │          0.00 │   2997866 │       │\n│ templates   │    4197 │      72.11 │ 834 │   14.33 │   0 │     0.00 │       789 │         13.56 │      5820 │       │\n│ kcl         │       0 │       0.00 │5594 │  100.00 │   0 │     0.00 │         0 │          0.00 │      5594 │       │\n╰─────────────┴─────────┴────────────┴─────┴─────────┴─────┴──────────┴───────────┴───────────────┴───────────┴───────╯\n\n📊 Overall Technology Distribution\n\n╭──────────────────────┬──────────┬────────────┬────────────────────────────────────────────────────╮\n│ technology           │ lines    │ percentage │ visual                                             │\n├──────────────────────┼──────────┼────────────┼────────────────────────────────────────────────────┤\n│ Nushell              │    74001 │       2.40 │ █                                                  │\n│ KCL                  │    10445 │       0.34 │                                                    │\n│ Rust                 │  2992107 │      96.93 │ ████████████████████████████████████████████████   │\n│ Templates (Tera)     │    10245 │       0.33 │                                                    │\n╰──────────────────────┴──────────┴────────────┴────────────────────────────────────────────────────╯\n\n📈 Total Lines of Code: 3086798\n```\n\n### JSON Format\n\n```\n{\n  "sections": [...],\n  "totals": {\n    "nushell": 74001,\n    "kcl": 10445,\n    "rust": 2992107,\n    "templates": 10245,\n    "grand_total": 3086798\n  },\n  "percentages": {\n    "nushell": 2.40,\n    "kcl": 0.34,\n    "rust": 96.93,\n    "templates": 0.33\n  }\n}\n```\n\n### Markdown Format\n\n```\n# Codebase Analysis\n\n## Technology Distribution\n\n| Technology | Lines | Percentage |\n|------------|-------|------------|\n| Nushell | 74001 | 2.40% |\n| KCL | 10445 | 0.34% |\n| Rust | 2992107 | 96.93% |\n| Templates | 10245 | 0.33% |\n| **TOTAL** | **3086798** | **100%** |\n```\n\n## Requirements\n\n- Nushell 0.107.1+\n- Access to the provisioning directory\n\n## What It Analyzes\n\n- ✅ All `.nu` files (Nushell scripts)\n- ✅ All `.k` files (KCL configuration)\n- ✅ All `.rs` files (Rust source)\n- ✅ All `.j2` and `.tera` files (Templates)\n\n## Notes\n\n- The script recursively searches all subdirectories\n- Empty sections show 0 for all technologies\n- Percentages are calculated per section and overall\n- Visual bars are proportional to percentage (max 50 chars = 100%)
