---
name: verification-quality
description: |
  Comprehensive truth scoring, code quality verification, and automatic rollback system with 0.95 accuracy threshold for ensuring high-quality agent outputs and codebase reliability.
---

# Verification & Quality Assurance Skill

## What This Skill Does

This skill provides a comprehensive verification and quality assurance system that ensures code quality and correctness through:

- **Truth Scoring**: Real-time reliability metrics (0.0-1.0 scale) for code, agents, and tasks
- **Verification Checks**: Automated code correctness, security, and best practices validation
- **Automatic Rollback**: Instant reversion of changes that fail verification (default threshold: 0.95)
- **Quality Metrics**: Statistical analysis with trends, confidence intervals, and improvement tracking
- **CI/CD Integration**: Export capabilities for continuous integration pipelines
- **Real-time Monitoring**: Live dashboards and watch modes for ongoing verification

## Prerequisites

- Monomind installed (`npx monomind@alpha`)
- Git repository (for rollback features)
- Node.js 18+ (for dashboard features)

## Quick Start

```bash
# View current truth scores
npx monomind@alpha truth

# Run verification check
npx monomind@alpha verify check

# Verify specific file with custom threshold
npx monomind@alpha verify check --file src/app.js --threshold 0.98

# Rollback last failed verification
npx monomind@alpha verify rollback --last-good
```

---

## Complete Guide

### Truth Scoring System

#### View Truth Metrics

Display comprehensive quality and reliability metrics for your codebase and agent tasks.

**Basic Usage:**

```bash
# View current truth scores (default: table format)
npx monomind@alpha truth

# View scores for specific time period
npx monomind@alpha truth --period 7d

# View scores for specific agent
npx monomind@alpha truth --agent coder --period 24h

# Find files/tasks below threshold
npx monomind@alpha truth --threshold 0.8
```

**Output Formats:**

```bash
# Table format (default)
npx monomind@alpha truth --format table

# JSON for programmatic access
npx monomind@alpha truth --format json

# CSV for spreadsheet analysis
npx monomind@alpha truth --format csv

# HTML report with visualizations
npx monomind@alpha truth --format html --export report.html
```

**Real-time Monitoring:**

```bash
# Watch mode with live updates
npx monomind@alpha truth --watch

# Export metrics automatically
npx monomind@alpha truth --export .monomind/metrics/truth-$(date +%Y%m%d).json
```

#### Truth Score Dashboard

Example dashboard output:

```
📊 Truth Metrics Dashboard
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Overall Truth Score: 0.947 ✅
Trend: ↗️ +2.3% (7d)

Top Performers:
  verification-agent   0.982 ⭐
  code-analyzer       0.971 ⭐
  test-generator      0.958 ✅

Needs Attention:
  refactor-agent      0.821 ⚠️
  docs-generator      0.794 ⚠️

Recent Tasks:
  task-456  0.991 ✅  "Implement auth"
  task-455  0.967 ✅  "Add tests"
  task-454  0.743 ❌  "Refactor API"
```

#### Metrics Explained

**Truth Scores (0.0-1.0):**

- `1.0-0.95`: Excellent (production-ready)
- `0.94-0.85`: Good (acceptable quality)
- `0.84-0.75`: Warning (needs attention)
- `<0.75`: Critical (requires immediate action)

**Trend Indicators:**

- ↗️ Improving (positive trend)
- → Stable (consistent performance)
- ↘️ Declining (quality regression detected)

**Statistics:**

- **Mean Score**: Average truth score across all measurements
- **Median Score**: Middle value (less affected by outliers)
- **Standard Deviation**: Consistency of scores (lower = more consistent)
- **Confidence Interval**: Statistical reliability of measurements

### Verification Checks

#### Run Verification

Execute comprehensive verification checks on code, tasks, or agent outputs.

**File Verification:**

```bash
# Verify single file
npx monomind@alpha verify check --file src/app.js

# Verify directory recursively
npx monomind@alpha verify check --directory src/

# Verify with auto-fix enabled
npx monomind@alpha verify check --file src/utils.js --auto-fix

# Verify current working directory
npx monomind@alpha verify check
```

**Task Verification:**

```bash
# Verify specific task output
npx monomind@alpha verify check --task task-123

# Verify with custom threshold
npx monomind@alpha verify check --task task-456 --threshold 0.99

# Verbose output for debugging
npx monomind@alpha verify check --task task-789 --verbose
```

**Batch Verification:**

```bash
# Verify multiple files in parallel
npx monomind@alpha verify batch --files "*.js" --parallel

# Verify with pattern matching
npx monomind@alpha verify batch --pattern "src/**/*.ts"

# Integration test suite
npx monomind@alpha verify integration --test-suite full
```

#### Verification Criteria

The verification system evaluates:

1. **Code Correctness**
   - Syntax validation
   - Type checking (TypeScript)
   - Logic flow analysis
   - Error handling completeness

2. **Best Practices**
   - Code style adherence
   - SOLID principles
   - Design patterns usage
   - Modularity and reusability

3. **Security**
   - Vulnerability scanning
   - Secret detection
   - Input validation
   - Authentication/authorization checks

4. **Performance**
   - Algorithmic complexity
   - Memory usage patterns
   - Database query optimization
   - Bundle size impact

5. **Documentation**
   - JSDoc/TypeDoc completeness
   - README accuracy
   - API documentation
   - Code comments quality

#### JSON Output for CI/CD

```bash
# Get structured JSON output
npx monomind@alpha verify check --json > verification.json

# Example JSON structure:
{
  "overallScore": 0.947,
  "passed": true,
  "threshold": 0.95,
  "checks": [
    {
      "name": "code-correctness",
      "score": 0.98,
      "passed": true
    },
    {
      "name": "security",
      "score": 0.91,
      "passed": false,
      "issues": [...]
    }
  ]
}
```

### Automatic Rollback

#### Rollback Failed Changes

Automatically revert changes that fail verification checks.

**Basic Rollback:**

```bash
# Rollback to last known good state
npx monomind@alpha verify rollback --last-good

# Rollback to specific commit
npx monomind@alpha verify rollback --to-commit abc123

# Interactive rollback with preview
npx monomind@alpha verify rollback --interactive
```

**Smart Rollback:**

```bash
# Rollback only failed files (preserve good changes)
npx monomind@alpha verify rollback --selective

# Rollback with automatic backup
npx monomind@alpha verify rollback --backup-first

# Dry-run mode (preview without executing)
npx monomind@alpha verify rollback --dry-run
```

**Rollback Performance:**

- Git-based rollback: <1 second
- Selective file rollback: <500ms
- Backup creation: Automatic before rollback

### Verification Reports

#### Generate Reports

Create detailed verification reports with metrics and visualizations.

**Report Formats:**

```bash
# JSON report
npx monomind@alpha verify report --format json

# HTML report with charts
npx monomind@alpha verify report --export metrics.html --format html

# CSV for data analysis
npx monomind@alpha verify report --format csv --export metrics.csv

# Markdown summary
npx monomind@alpha verify report --format markdown
```

**Time-based Reports:**

```bash
# Last 24 hours
npx monomind@alpha verify report --period 24h

# Last 7 days
npx monomind@alpha verify report --period 7d

# Last 30 days with trends
npx monomind@alpha verify report --period 30d --include-trends

# Custom date range
npx monomind@alpha verify report --from 2025-01-01 --to 2025-01-31
```

**Report Content:**

- Overall truth scores
- Per-agent performance metrics
- Task completion quality
- Verification pass/fail rates
- Rollback frequency
- Quality improvement trends
- Statistical confidence intervals

### Interactive Dashboard

#### Launch Dashboard

Run interactive web-based verification dashboard with real-time updates.

```bash
# Launch dashboard on default port (3000)
npx monomind@alpha verify dashboard

# Custom port
npx monomind@alpha verify dashboard --port 8080

# Export dashboard data
npx monomind@alpha verify dashboard --export

# Dashboard with auto-refresh
npx monomind@alpha verify dashboard --refresh 5s
```

**Dashboard Features:**

- Real-time truth score updates (WebSocket)
- Interactive charts and graphs
- Agent performance comparison
- Task history timeline
- Rollback history viewer
- Export to PDF/HTML
- Filter by time period/agent/score

### Configuration

#### Default Configuration

Set verification preferences in `.monomind/config.json`:

```json
{
  "verification": {
    "threshold": 0.95,
    "autoRollback": true,
    "gitIntegration": true,
    "hooks": {
      "preCommit": true,
      "preTask": true,
      "postEdit": true
    },
    "checks": {
      "codeCorrectness": true,
      "security": true,
      "performance": true,
      "documentation": true,
      "bestPractices": true
    }
  },
  "truth": {
    "defaultFormat": "table",
    "defaultPeriod": "24h",
    "warningThreshold": 0.85,
    "criticalThreshold": 0.75,
    "autoExport": {
      "enabled": true,
      "path": ".monomind/metrics/truth-daily.json"
    }
  }
}
```

#### Threshold Configuration

**Adjust verification strictness:**

```bash
# Strict mode (99% accuracy required)
npx monomind@alpha verify check --threshold 0.99

# Lenient mode (90% acceptable)
npx monomind@alpha verify check --threshold 0.90

# Set default threshold
npx monomind@alpha config set verification.threshold 0.98
```

**Per-environment thresholds:**

```json
{
  "verification": {
    "thresholds": {
      "production": 0.99,
      "staging": 0.95,
      "development": 0.9
    }
  }
}
```

### Integration Examples

#### CI/CD Integration

**GitHub Actions:**

```yaml
name: Quality Verification

on: [push, pull_request]

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1

      - name: Install Dependencies
        run: npm install

      - name: Run Verification
        run: |
          npx monomind@alpha verify check --json > verification.json

      - name: Check Truth Score
        run: |
          score=$(jq '.overallScore' verification.json)
          if (( $(echo "$score < 0.95" | bc -l) )); then
            echo "Truth score too low: $score"
            exit 1
          fi

      - name: Upload Report
        uses: actions/upload-artifact@v1
        with:
          name: verification-report
          path: verification.json
```

**GitLab CI:**

```yaml
verify:
  stage: test
  script:
    - npx monomind@alpha verify check --threshold 0.95 --json > verification.json
    - |
      score=$(jq '.overallScore' verification.json)
      if [ $(echo "$score < 0.95" | bc) -eq 1 ]; then
        echo "Verification failed with score: $score"
        exit 1
      fi
  artifacts:
    paths:
      - verification.json
    reports:
      junit: verification.json
```

#### Swarm Integration

Run verification automatically during swarm operations:

```bash
# Swarm with verification enabled
npx monomind@alpha swarm --verify --threshold 0.98

# Hive Mind with auto-rollback
npx monomind@alpha hive-mind --verify --rollback-on-fail

# Training pipeline with verification
npx monomind@alpha train --verify --threshold 0.99
```

#### Pair Programming Integration

Enable real-time verification during collaborative development:

```bash
# Pair with verification
npx monomind@alpha pair --verify --real-time

# Pair with custom threshold
npx monomind@alpha pair --verify --threshold 0.97 --auto-fix
```

### Advanced Workflows

#### Continuous Verification

Monitor codebase continuously during development:

```bash
# Watch directory for changes
npx monomind@alpha verify watch --directory src/

# Watch with auto-fix
npx monomind@alpha verify watch --directory src/ --auto-fix

# Watch with notifications
npx monomind@alpha verify watch --notify --threshold 0.95
```

#### Monitoring Integration

Send metrics to external monitoring systems:

```bash
# Export to Prometheus
npx monomind@alpha truth --format json | \
  curl -X POST https://pushgateway.example.com/metrics/job/monomind \
  -d @-

# Send to DataDog
npx monomind@alpha verify report --format json | \
  curl -X POST "https://api.datadoghq.com/api/v1/series?api_key=${DD_API_KEY}" \
  -H "Content-Type: application/json" \
  -d @-

# Custom webhook
npx monomind@alpha truth --format json | \
  curl -X POST https://metrics.example.com/api/truth \
  -H "Content-Type: application/json" \
  -d @-
```

#### Pre-commit Hooks

Automatically verify before commits:

```bash
# Install pre-commit hook
npx monomind@alpha verify install-hook --pre-commit

# .git/hooks/pre-commit example:
#!/bin/bash
npx monomind@alpha verify check --threshold 0.95 --json > /tmp/verify.json

score=$(jq '.overallScore' /tmp/verify.json)
if (( $(echo "$score < 0.95" | bc -l) )); then
  echo "❌ Verification failed with score: $score"
  echo "Run 'npx monomind@alpha verify check --verbose' for details"
  exit 1
fi

echo "✅ Verification passed with score: $score"
```

### Performance Metrics

**Verification Speed:**

- Single file check: <100ms
- Directory scan: <500ms (per 100 files)
- Full codebase analysis: <5s (typical project)
- Truth score calculation: <50ms

**Rollback Speed:**

- Git-based rollback: <1s
- Selective file rollback: <500ms
- Backup creation: <2s

**Dashboard Performance:**

- Initial load: <1s
- Real-time updates: <100ms latency (WebSocket)
- Chart rendering: 60 FPS

### Troubleshooting

#### Common Issues

**Low Truth Scores:**

```bash
# Get detailed breakdown
npx monomind@alpha truth --verbose --threshold 0.0

# Check specific criteria
npx monomind@alpha verify check --verbose

# View agent-specific issues
npx monomind@alpha truth --agent <agent-name> --format json
```

**Rollback Failures:**

```bash
# Check git status
git status

# View rollback history
npx monomind@alpha verify rollback --history

# Manual rollback
git reset --hard HEAD~1
```

**Verification Timeouts:**

```bash
# Increase timeout
npx monomind@alpha verify check --timeout 60s

# Verify in batches
npx monomind@alpha verify batch --batch-size 10
```

### Exit Codes

Verification commands return standard exit codes:

- `0`: Verification passed (score ≥ threshold)
- `1`: Verification failed (score < threshold)
- `2`: Error during verification (invalid input, system error)

### Related Commands

- `npx monomind@alpha pair` - Collaborative development with verification
- `npx monomind@alpha train` - Training with verification feedback
- `npx monomind@alpha swarm` - Multi-agent coordination with quality checks
- `npx monomind@alpha report` - Generate comprehensive project reports

### Best Practices

1. **Set Appropriate Thresholds**: Use 0.99 for critical code, 0.95 for standard, 0.90 for experimental
2. **Enable Auto-rollback**: Prevent bad code from persisting
3. **Monitor Trends**: Track improvement over time, not just current scores
4. **Integrate with CI/CD**: Make verification part of your pipeline
5. **Use Watch Mode**: Get immediate feedback during development
6. **Export Metrics**: Track quality metrics in your monitoring system
7. **Review Rollbacks**: Understand why changes were rejected
8. **Train Agents**: Use verification feedback to improve agent performance

### Additional Resources

- Truth Scoring Algorithm: See `/docs/truth-scoring.md`
- Verification Criteria: See `/docs/verification-criteria.md`
- Integration Examples: See `/examples/verification/`
- API Reference: See `/docs/api/verification.md`
