provisioning/tools/README-analyze-codebase.md
Jesús Pérez 44648e3206
chore: complete nickel migration and consolidate legacy configs
- Remove KCL ecosystem (~220 files deleted)
- Migrate all infrastructure to Nickel schema system
- Consolidate documentation: legacy docs → provisioning/docs/src/
- Add CI/CD workflows (.github/) and Rust build config (.cargo/)
- Update core system for Nickel schema parsing
- Update README.md and CHANGES.md for v5.0.0 release
- Fix pre-commit hooks: end-of-file, trailing-whitespace
- Breaking changes: KCL workspaces require migration
- Migration bridge available in docs/src/development/
2026-01-08 09:55:37 +00:00

6.3 KiB

Codebase Analysis Script

Script to analyze the technology distribution in the provisioning codebase.

Usage

Basic Usage

# From provisioning directory (analyzes current directory)
cd provisioning
nu tools/analyze-codebase.nu

# From project root, analyze provisioning
nu provisioning/tools/analyze-codebase.nu --path provisioning

# Analyze any path
nu provisioning/tools/analyze-codebase.nu --path /absolute/path/to/directory
```plaintext

### Output Formats

```bash
# Table format (default) - colored, visual bars
nu provisioning/tools/analyze-codebase.nu --format table

# JSON format - for programmatic use
nu provisioning/tools/analyze-codebase.nu --format json

# Markdown format - for documentation
nu provisioning/tools/analyze-codebase.nu --format markdown
```plaintext

### From provisioning directory

```bash
cd provisioning
nu tools/analyze-codebase.nu
```plaintext

### Direct execution (if in PATH)

```bash
# Make it globally available (one time)
ln -sf "$(pwd)/provisioning/tools/analyze-codebase.nu" /usr/local/bin/analyze-codebase

# Then run from anywhere
analyze-codebase
analyze-codebase --format json
analyze-codebase --format markdown > CODEBASE_STATS.md
```plaintext

## Output

The script analyzes:

- **Nushell** (.nu files)
- **KCL** (.k files)
- **Rust** (.rs files)
- **Templates** (.j2, .tera files)

Across these sections:

- `core/` - CLI interface, core libraries
- `extensions/` - Providers, taskservs, clusters
- `platform/` - Rust services (orchestrator, control-center, etc.)
- `templates/` - Template files
- `kcl/` - KCL configuration schemas

## Example Output

### Table Format

```plaintext
📊 Analyzing Codebase: provisioning

📋 Lines of Code by Section

╭─────────────┬─────────┬────────────┬─────┬─────────┬─────┬──────────┬───────────┬───────────────┬───────────┬───────╮
│ section     │ nushell │ nushell_pct│ kcl │ kcl_pct │ rust│ rust_pct │ templates │ templates_pct │ total     │       │
├─────────────┼─────────┼────────────┼─────┼─────────┼─────┼──────────┼───────────┼───────────────┼───────────┼───────┤
│ core        │   53843 │      99.87 │  71 │    0.13 │   0 │     0.00 │         0 │          0.00 │     53914 │       │
│ extensions  │   10202 │      43.21 │3946 │   16.72 │   0 │     0.00 │      9456 │         40.05 │     23604 │       │
│ platform    │    5759 │       0.19 │   0 │    0.00 │2992107│  99.81 │         0 │          0.00 │   2997866 │       │
│ templates   │    4197 │      72.11 │ 834 │   14.33 │   0 │     0.00 │       789 │         13.56 │      5820 │       │
│ kcl         │       0 │       0.00 │5594 │  100.00 │   0 │     0.00 │         0 │          0.00 │      5594 │       │
╰─────────────┴─────────┴────────────┴─────┴─────────┴─────┴──────────┴───────────┴───────────────┴───────────┴───────╯

📊 Overall Technology Distribution

╭──────────────────────┬──────────┬────────────┬────────────────────────────────────────────────────╮
│ technology           │ lines    │ percentage │ visual                                             │
├──────────────────────┼──────────┼────────────┼────────────────────────────────────────────────────┤
│ Nushell              │    74001 │       2.40 │ █                                                  │
│ KCL                  │    10445 │       0.34 │                                                    │
│ Rust                 │  2992107 │      96.93 │ ████████████████████████████████████████████████   │
│ Templates (Tera)10245 │       0.33 │                                                    │
╰──────────────────────┴──────────┴────────────┴────────────────────────────────────────────────────╯

📈 Total Lines of Code: 3086798
```plaintext

### JSON Format

```json
{
  "sections": [...],
  "totals": {
    "nushell": 74001,
    "kcl": 10445,
    "rust": 2992107,
    "templates": 10245,
    "grand_total": 3086798
  },
  "percentages": {
    "nushell": 2.40,
    "kcl": 0.34,
    "rust": 96.93,
    "templates": 0.33
  }
}
```plaintext

### Markdown Format

```markdown
# Codebase Analysis

## Technology Distribution

| Technology | Lines | Percentage |
|------------|-------|------------|
| Nushell | 74001 | 2.40% |
| KCL | 10445 | 0.34% |
| Rust | 2992107 | 96.93% |
| Templates | 10245 | 0.33% |
| **TOTAL** | **3086798** | **100%** |
```plaintext

## Requirements

- Nushell 0.107.1+
- Access to the provisioning directory

## What It Analyzes

- ✅ All `.nu` files (Nushell scripts)
- ✅ All `.k` files (KCL configuration)
- ✅ All `.rs` files (Rust source)
- ✅ All `.j2` and `.tera` files (Templates)

## Notes

- The script recursively searches all subdirectories
- Empty sections show 0 for all technologies
- Percentages are calculated per section and overall
- Visual bars are proportional to percentage (max 50 chars = 100%)