pmat 3.11.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
# Excellence Tracker

## Overview

The Excellence Tracker is a comprehensive code quality monitoring system that tracks multiple dimensions of software excellence. It provides actionable insights into code quality trends, helping teams maintain high standards and identify areas for improvement.

## Metrics Tracked

### 1. **Test Coverage**
- Line coverage percentage
- Branch coverage percentage
- Function coverage percentage
- Uncovered critical paths

### 2. **Code Complexity**
- Cyclomatic complexity distribution
- Cognitive complexity trends
- Hotspot identification
- Complexity reduction over time

### 3. **Type Safety**
- Type annotation coverage
- `any` usage in TypeScript
- Unsafe code blocks in Rust
- Type inference quality

### 4. **Documentation Quality**
- Public API documentation coverage
- Example code presence
- README completeness
- Inline comment density

### 5. **Performance Metrics**
- Build times
- Test execution speed
- Binary size trends
- Memory usage patterns

### 6. **Dependency Health**
- Outdated dependencies
- Security vulnerabilities
- License compliance
- Dependency tree depth

## Usage

### Command Line Interface

```bash
# Generate excellence report
pmat excellence-tracker

# Track specific metrics
pmat excellence-tracker --metrics coverage,complexity,docs

# Compare with baseline
pmat excellence-tracker --baseline excellence-baseline.json

# Output formats
pmat excellence-tracker --format json > excellence-report.json
pmat excellence-tracker --format markdown > EXCELLENCE_REPORT.md

# Watch mode for continuous tracking
pmat excellence-tracker --watch
```

### Configuration

```toml
# excellence-config.toml
[metrics]
enabled = ["coverage", "complexity", "types", "docs", "performance", "deps"]

[thresholds]
min_coverage = 80.0
max_complexity = 20
min_doc_coverage = 70.0
max_build_time = "2m"

[reporting]
include_trends = true
trend_window = "30d"
generate_badges = true

[notifications]
slack_webhook = "https://hooks.slack.com/..."
email = "team@example.com"
threshold_alerts = true
```

## Report Format

### Summary Dashboard

```markdown
# Excellence Report - 2024-06-09

## Overall Score: 87/100 🟢

### Metrics Summary
- ✅ Test Coverage: 92.3% (+2.1%)
- ⚠️ Code Complexity: 18.5 (target: <15)
- ✅ Type Safety: 98.2%
- ✅ Documentation: 85.7%
- ✅ Build Performance: 1m 32s
- ⚠️ Dependencies: 3 outdated, 1 security issue

### Trends (Last 30 Days)
📈 Coverage: +5.2%
📉 Complexity: -12.3%
📈 Type Safety: +3.1%
➡️ Documentation: +0.2%
```

### Detailed Metrics

#### Test Coverage Report
```
┌─────────────────────────────────────────┐
│ File Coverage Distribution              │
├─────────────────────────────────────────┤
│ 90-100%: ████████████████████ (142)    │
│ 80-90%:  ██████ (45)                   │
│ 70-80%:  ███ (23)                      │
│ <70%:    ██ (15)                       │
└─────────────────────────────────────────┘

Top Uncovered Files:
1. src/experimental/ai_engine.rs (45.2%)
2. src/utils/legacy_converter.rs (52.1%)
3. src/demo/mock_server.rs (61.3%)
```

#### Complexity Hotspots
```
┌─────────────────────────────────────────┐
│ Function               │ Cyclo │ Cogn  │
├─────────────────────────────────────────┤
│ handle_analyze_graph   │  75   │ 125   │
│ process_ast_nodes      │  45   │  67   │
│ validate_complex_input │  38   │  52   │
│ merge_configurations   │  32   │  48   │
└─────────────────────────────────────────┘
```

## Integration

### GitHub Actions

```yaml
name: Excellence Tracking
on:
  push:
    branches: [main]
  schedule:
    - cron: '0 0 * * 0' # Weekly

jobs:
  track-excellence:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Install PMAT
        run: |
          curl -sSfL https://raw.githubusercontent.com/paiml/paiml-mcp-agent-toolkit/master/scripts/install.sh | sh
      
      - name: Run Excellence Tracker
        run: |
          pmat excellence-tracker \
            --baseline .excellence/baseline.json \
            --format markdown > excellence-report.md
      
      - name: Update README Badge
        run: |
          score=$(pmat excellence-tracker --format json | jq .overall_score)
          # Update badge in README
      
      - name: Comment on PR
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v6
        with:
          script: |
            const report = fs.readFileSync('excellence-report.md', 'utf8');
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: report
            });
```

### Pre-commit Hook

```bash
#!/bin/bash
# .git/hooks/pre-commit

# Check excellence metrics
pmat excellence-tracker --quick-check
if [ $? -ne 0 ]; then
    echo "❌ Excellence standards not met!"
    echo "Run 'pmat excellence-tracker' for details"
    exit 1
fi
```

## Scoring Algorithm

The overall excellence score is calculated using weighted metrics:

```
Score = (
    Coverage * 0.25 +
    (100 - Complexity) * 0.20 +
    TypeSafety * 0.20 +
    Documentation * 0.15 +
    Performance * 0.10 +
    DependencyHealth * 0.10
)
```

### Metric Calculations

#### Coverage Score
```
coverage_score = (line_coverage * 0.5 + branch_coverage * 0.3 + function_coverage * 0.2)
```

#### Complexity Score
```
complexity_score = 100 * (1 - (avg_complexity / max_allowed_complexity))
```

#### Type Safety Score
```
type_safety_score = 100 * (typed_lines / total_lines) * (1 - unsafe_usage_ratio)
```

## Trend Analysis

### Visualization

```
Coverage Trend (Last 30 Days)
100 ┤                                    ╭─
 95 ┤                              ╭─────╯
 90 ┤                        ╭─────╯
 85 ┤                  ╭─────╯
 80 ┤            ╭─────╯
 75 ┤      ╭─────╯
 70 ┤──────╯
    └─────────────────────────────────────
     May 10        May 20        May 30
```

### Alerts and Notifications

```json
{
  "alert": {
    "type": "threshold_breach",
    "metric": "complexity",
    "current": 22.5,
    "threshold": 20,
    "trend": "increasing",
    "files_affected": [
      "src/cli/mod.rs",
      "src/services/analyzer.rs"
    ],
    "recommendation": "Consider refactoring high-complexity functions"
  }
}
```

## Best Practices

1. **Set Realistic Thresholds**: Start with achievable goals and gradually increase
2. **Track Trends**: Focus on improvement over time rather than absolute values
3. **Automate Monitoring**: Integrate with CI/CD for continuous tracking
4. **Team Visibility**: Share reports in team channels or dashboards
5. **Act on Insights**: Use data to guide refactoring and improvement efforts

## Custom Metrics

### Adding Custom Metrics

```rust
use paiml_mcp_agent_toolkit::excellence::{Metric, MetricResult};

pub struct SecurityMetric;

impl Metric for SecurityMetric {
    fn name(&self) -> &'static str {
        "security"
    }
    
    fn calculate(&self, project: &Project) -> MetricResult {
        let vulnerabilities = scan_vulnerabilities(project);
        let score = 100.0 * (1.0 - (vulnerabilities.len() as f32 / 100.0));
        
        MetricResult {
            score,
            details: json!({
                "vulnerabilities": vulnerabilities,
                "last_scan": Utc::now()
            })
        }
    }
}
```

### Registering Custom Metrics

```toml
# excellence-config.toml
[custom_metrics]
security = { path = "./metrics/security.wasm", weight = 0.15 }
accessibility = { path = "./metrics/a11y.wasm", weight = 0.10 }
```

## Data Export

### JSON Schema

```json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "timestamp": { "type": "string", "format": "date-time" },
    "overall_score": { "type": "number", "minimum": 0, "maximum": 100 },
    "metrics": {
      "type": "object",
      "properties": {
        "coverage": { "$ref": "#/definitions/metric" },
        "complexity": { "$ref": "#/definitions/metric" },
        "type_safety": { "$ref": "#/definitions/metric" },
        "documentation": { "$ref": "#/definitions/metric" },
        "performance": { "$ref": "#/definitions/metric" },
        "dependencies": { "$ref": "#/definitions/metric" }
      }
    },
    "trends": {
      "type": "array",
      "items": { "$ref": "#/definitions/trend" }
    }
  }
}
```

### CSV Export

```csv
timestamp,overall_score,coverage,complexity,type_safety,documentation,performance,dependencies
2024-06-09T10:00:00Z,87,92.3,18.5,98.2,85.7,95.0,78.5
2024-06-08T10:00:00Z,85,90.2,20.1,95.1,85.5,94.8,75.2
```

## Troubleshooting

### Common Issues

**Q: Excellence tracker is slow**
A: Use `--quick-check` for faster results or adjust the analysis depth in config.

**Q: Metrics seem incorrect**
A: Ensure all build artifacts are fresh. Run `make clean && make build` first.

**Q: Missing coverage data**
A: Make sure tests are run with coverage enabled: `cargo test --coverage`

## Future Enhancements

- **AI-Powered Insights**: ML-based recommendations for improvement
- **Team Dashboards**: Web interface for team-wide visibility
- **Historical Analysis**: Long-term trend analysis and predictions
- **Gamification**: Achievements and leaderboards for motivation
- **IDE Integration**: Real-time excellence metrics in your editor