Claude
Skills
Sign in
Back

complexity-scorer

Included with Lifetime
$97 forever

Score task complexity using keyword matching and heuristics

bashbashcomplexityscoringkeywordsanalysisclassification

What this skill does


# Complexity Scorer

Patterns for scoring task complexity using keyword matching, context analysis, and configurable heuristics. Extracted from workspace-hub's model selection system.

## When to Use This Skill

✅ **Use when:**
- Routing tasks to different handlers based on complexity
- Recommending resources (models, workers, time estimates)
- Prioritizing work items
- Auto-classifying incoming requests
- Building intelligent dispatchers

❌ **Avoid when:**
- Simple yes/no classification
- When ML-based classification is more appropriate
- Highly domain-specific scoring that requires expertise

## Core Capabilities

### 1. Keyword-Based Scoring

Define keyword categories with weights:

```bash
#!/bin/bash
# ABOUTME: Keyword-based complexity scoring
# ABOUTME: Pattern from workspace-hub suggest_model.sh

# Keyword categories with associated complexity impact
# High complexity keywords (score +3)
HIGH_COMPLEXITY="architecture|refactor|design|security|complex|multi-file|algorithm|optimization|strategy|planning|cross-repository|performance|migration|integration"

# Medium complexity keywords (score +1)
MEDIUM_COMPLEXITY="implement|feature|bug|fix|code review|documentation|test|update|add|create|build|configure|setup"

# Low complexity keywords (score -2)
LOW_COMPLEXITY="check|status|simple|quick|template|list|grep|find|search|summary|validation|exists|show|display|count|verify"

# Score based on keywords
score_keywords() {
    local text="$1"
    local text_lower=$(echo "$text" | tr '[:upper:]' '[:lower:]')
    local score=0

    # Check high complexity first (mutually exclusive)
    if echo "$text_lower" | grep -qE "$HIGH_COMPLEXITY"; then
        ((score+=3))
    elif echo "$text_lower" | grep -qE "$MEDIUM_COMPLEXITY"; then
        ((score+=1))
    elif echo "$text_lower" | grep -qE "$LOW_COMPLEXITY"; then
        ((score-=2))
    fi

    echo $score
}

# Usage
task="Design the authentication system architecture"
score=$(score_keywords "$task")
echo "Complexity score: $score"  # Output: 3
```

### 2. Multi-Factor Scoring

Combine multiple factors for better accuracy:

```bash
#!/bin/bash
# ABOUTME: Multi-factor complexity scoring
# ABOUTME: Combines keywords, length, context

# Factor weights
declare -A WEIGHTS=(
    ["keywords"]=3
    ["length"]=1
    ["urgency"]=1
    ["scope"]=2
)

# Score task length
score_length() {
    local text="$1"
    local word_count=$(echo "$text" | wc -w)

    if [[ $word_count -gt 20 ]]; then
        echo 2  # Long = more complex
    elif [[ $word_count -gt 10 ]]; then
        echo 1
    elif [[ $word_count -lt 5 ]]; then
        echo -1  # Short = simpler
    else
        echo 0
    fi
}

# Score urgency indicators
score_urgency() {
    local text="$1"
    local text_lower=$(echo "$text" | tr '[:upper:]' '[:lower:]')

    if echo "$text_lower" | grep -qE "urgent|asap|critical|emergency|immediately"; then
        echo 2
    elif echo "$text_lower" | grep -qE "soon|priority|important"; then
        echo 1
    else
        echo 0
    fi
}

# Score scope indicators
score_scope() {
    local text="$1"
    local text_lower=$(echo "$text" | tr '[:upper:]' '[:lower:]')

    if echo "$text_lower" | grep -qE "all|every|entire|complete|full|comprehensive"; then
        echo 2
    elif echo "$text_lower" | grep -qE "multiple|several|various|many"; then
        echo 1
    elif echo "$text_lower" | grep -qE "single|one|specific|particular"; then
        echo -1
    else
        echo 0
    fi
}

# Combined scoring
calculate_complexity() {
    local text="$1"
    local total=0

    local keyword_score=$(score_keywords "$text")
    local length_score=$(score_length "$text")
    local urgency_score=$(score_urgency "$text")
    local scope_score=$(score_scope "$text")

    total=$((keyword_score * ${WEIGHTS[keywords]} +
             length_score * ${WEIGHTS[length]} +
             urgency_score * ${WEIGHTS[urgency]} +
             scope_score * ${WEIGHTS[scope]}))

    echo $total
}
```

### 3. Context-Aware Scoring

Adjust scores based on context (repository, domain, etc.):

```bash
#!/bin/bash
# ABOUTME: Context-aware complexity scoring
# ABOUTME: Adjusts based on repository tier, domain

# Repository tiers
TIER1_REPOS="workspace-hub|digitalmodel|energy|frontierdeepwater"
TIER2_REPOS="aceengineercode|assetutilities|worldenergydata|rock-oil-field"
TIER3_REPOS="doris|saipem|OGManufacturing|seanation"
PERSONAL_ACTIVE="aceengineer-admin|aceengineer-website"
PERSONAL_EXPERIMENTAL="hobbies|sd-work|acma-projects"

# Get repository tier
get_repo_tier() {
    local repo="$1"

    if echo "$repo" | grep -qE "$TIER1_REPOS"; then
        echo "tier1"
    elif echo "$repo" | grep -qE "$TIER2_REPOS"; then
        echo "tier2"
    elif echo "$repo" | grep -qE "$TIER3_REPOS"; then
        echo "tier3"
    elif echo "$repo" | grep -qE "$PERSONAL_ACTIVE"; then
        echo "personal_active"
    elif echo "$repo" | grep -qE "$PERSONAL_EXPERIMENTAL"; then
        echo "personal_experimental"
    else
        echo "unknown"
    fi
}

# Adjust score based on context
adjust_for_context() {
    local base_score="$1"
    local repo="$2"
    local adjusted=$base_score

    local tier=$(get_repo_tier "$repo")

    case "$tier" in
        tier1)
            # Production repos bias toward higher quality
            ((adjusted+=1))
            ;;
        tier3|personal_experimental)
            # Maintenance/experimental bias toward efficiency
            ((adjusted-=1))
            ;;
    esac

    echo $adjusted
}

# Full scoring with context
score_with_context() {
    local task="$1"
    local repo="$2"

    local base_score=$(calculate_complexity "$task")
    local final_score=$(adjust_for_context "$base_score" "$repo")

    echo $final_score
}
```

### 4. Score Classification

Map scores to categories:

```bash
#!/bin/bash
# ABOUTME: Map complexity scores to categories
# ABOUTME: Provides actionable classifications

# Classification thresholds
THRESHOLD_HIGH=5
THRESHOLD_MEDIUM=1
THRESHOLD_LOW=-2

# Classify score
classify_complexity() {
    local score="$1"

    if [[ $score -ge $THRESHOLD_HIGH ]]; then
        echo "high"
    elif [[ $score -ge $THRESHOLD_MEDIUM ]]; then
        echo "medium"
    elif [[ $score -ge $THRESHOLD_LOW ]]; then
        echo "low"
    else
        echo "trivial"
    fi
}

# Get recommendation based on classification
get_recommendation() {
    local score="$1"
    local classification=$(classify_complexity "$score")

    case "$classification" in
        high)
            echo "OPUS"
            echo "Use for complex architecture, multi-file refactoring, security analysis"
            ;;
        medium)
            echo "SONNET"
            echo "Standard implementation, code review, documentation"
            ;;
        low)
            echo "HAIKU"
            echo "Quick queries, status checks, simple operations"
            ;;
        trivial)
            echo "HAIKU"
            echo "Trivial task - consider if AI is even needed"
            ;;
    esac
}

# Get color for display
get_score_color() {
    local score="$1"
    local classification=$(classify_complexity "$score")

    case "$classification" in
        high)    echo "$GREEN" ;;
        medium)  echo "$BLUE" ;;
        low)     echo "$YELLOW" ;;
        trivial) echo "$CYAN" ;;
    esac
}
```

### 5. Confidence Scoring

Add confidence to scoring:

```bash
#!/bin/bash
# ABOUTME: Confidence scoring for complexity estimates
# ABOUTME: Indicates reliability of the score

# Calculate confidence
calculate_confidence() {
    local text="$1"
    local confidence=50  # Base confidence

    local word_count=$(echo "$text" | wc -w)
    local keyword_matches=0
    local text_lower=$(echo "$text" | tr '[:upper:]' '[:lower:]')

    # More words = higher confidence (more context)
    if [[ $word_count -gt 15 ]]; then
        ((confidence+=20))
    elif [[ $word_count -gt 8 ]]; then
        ((confidence+=10))
    elif [[ $word_count -lt 3 ]]; then
        ((confidence-=20))
    fi

Related in bash