# team-role-discovery

Discovers and validates team member roles through multi-source analysis, enabling smart assignment and role-based reporting.

## Purpose

Automatically discover team members and their roles by analyzing:

- Git commit history and patterns
- JIRA project membership and permissions
- Issue assignment and activity history
- Code ownership and specialization areas
- BMAD agent usage patterns

## Discovery Methods

### 1. Git Author Analysis

```bash
# Analyze recent Git contributors
git log --format='%ae|%an' --since='90 days ago' | sort | uniq -c | sort -rn

# Analyze code areas per author
git log --format='%ae' --name-only --since='90 days ago' | \
  awk 'NF==0{author=""} /@/{author=$0} NF>0&&author{print author":"$0}' | \
  grep -E '\.(js|ts|py|java|go)$' | sort | uniq -c | sort -rn
```

### 2. JIRA User Discovery

[[LLM: Use MCP tools to:

1. Get project members: mcp**mcp-atlassian**jira_search with JQL "project = PROJECT_KEY"
2. Extract unique assignees from recent issues
3. Get user details and project roles
4. Match email patterns between Git and JIRA
   ]]

### 3. Role Pattern Detection

**Developer Indicators**:

- Creates feature branches (feature/_, feat/_)
- Commits to src/, lib/, or similar code directories
- Opens pull requests
- Assigned to Story or Task issues

**Senior Developer Indicators**:

- Reviews others' PRs (GitHub/GitLab API if available)
- Makes commits to critical paths (core/, auth/, etc.)
- Handles complex refactoring commits
- Mentors in PR comments

**QA Engineer Indicators**:

- Creates or modifies test files (_test_, _spec_)
- Reports Bug issues in JIRA
- Assigned to Test or QA Task issues
- Commits to test/ or qa/ directories

**DevOps Engineer Indicators**:

- Modifies CI/CD files (.github/workflows, .gitlab-ci.yml, Jenkinsfile)
- Commits to infrastructure code (terraform/, k8s/, docker/)
- Handles Deployment or Infrastructure issues
- Creates deployment tags

**Product Owner Indicators**:

- Creates Epic issues
- Updates issue priorities
- Defines acceptance criteria
- Minimal code commits

**Tech Lead Indicators**:

- Approves critical PRs
- Creates architectural decision records (ADRs)
- Assigns technical tasks to others
- High code review to commit ratio

### 4. Specialization Detection

```yaml
specialization_patterns:
  frontend:
    - "*.jsx"
    - "*.tsx"
    - "*.vue"
    - "components/"
    - "styles/"
  backend:
    - "api/"
    - "server/"
    - "*.controller.*"
    - "*.service.*"
  database:
    - "migrations/"
    - "*.sql"
    - "schema/"
  mobile:
    - "ios/"
    - "android/"
    - "*.swift"
    - "*.kotlin"
```

### 5. Activity Pattern Analysis

[[LLM: Analyze team member activity:

1. Average issues per sprint
2. Issue type distribution
3. Code review participation
4. Commit frequency and size
5. Working hours (timezone detection)
   ]]

## Output Format

```yaml
team_members:
  - jira_username: "john.doe@company.com"
    display_name: "John Doe"
    git_emails:
      - "john.doe@company.com"
      - "jdoe@github.com"

    # Role information
    primary_role: "senior_developer"
    secondary_roles:
      - "tech_lead"
    confidence: 0.85
    role_indicators:
      - "Reviews 80% of team PRs"
      - "Owns auth and core modules"
      - "Mentors junior developers"

    # Specializations
    specializations:
      - "backend"
      - "security"
    code_ownership:
      - "src/auth/**"
      - "src/core/**"
      - "lib/security/**"

    # BMAD preferences
    preferred_agents:
      - "architect"
      - "developer"
      - "reviewer"

    # Activity metrics
    activity:
      typical_issue_types:
        - "Story"
        - "Technical Task"
      avg_issues_per_sprint: 8
      code_review_ratio: 3.2 # reviews given/received
      commit_frequency: "daily"
      avg_commit_size: "medium"

    # Availability
    availability:
      timezone: "America/New_York"
      typical_hours: "9-5 EST"
      capacity_percentage: 100
```

## Validation Rules

```yaml
validation:
  # Minimum thresholds
  min_activity:
    commits: 5
    jira_actions: 10
    days_active: 30

  # Confidence scoring
  confidence_factors:
    git_commits: 0.3
    jira_activity: 0.3
    pattern_match: 0.2
    peer_review: 0.2

  # Role conflicts
  incompatible_roles:
    - ["product_owner", "developer"]
    - ["qa_engineer", "devops_engineer"]
```

## Usage

```markdown
# During setup

"Let me discover your team members..."
[[Use team-role-discovery to analyze Git and JIRA]]

# Manual discovery

"jira team discover"
[[Use team-role-discovery with current project config]]

# Add specific member

"jira team add john.doe@company.com"
[[Use team-role-discovery for single user]]

# Update roles

"jira team update john.doe@company.com --role tech_lead"
[[Update configuration with new role]]
```

## Integration Points

1. **Setup Process**: Auto-discover during initial configuration
2. **Smart Assignment**: Use role data for intelligent issue assignment
3. **Reports**: Generate role-based productivity metrics
4. **BMAD Agents**: Map team members to their preferred agents
5. **Capacity Planning**: Track team capacity and workload

## Privacy Considerations

- Only analyze publicly available Git data
- Respect JIRA permissions and visibility
- Allow opt-out for team members
- Store only necessary information
- Provide transparency about collected data
