# Author Collaboration Network

- **Command:** `lore collaboration [--since <date>]`
- **Confidence:** 70%
- **Tier:** 3
- **Status:** proposed
- **Effort:** medium — self-join on notes, graph construction

## What

Build a weighted graph of author pairs: (author_A, author_B, weight) where weight =
number of times A reviewed B's MR + B reviewed A's MR + they both commented on the
same entity.

## Why

Reveals team structure empirically. Shows who collaborates across team boundaries
and where knowledge transfer happens. Useful for re-orgs, onboarding planning,
and identifying isolated team members.

## Data Required

All exists today:
- `merge_requests` (author_username)
- `notes` (author_username, note_type='DiffNote')
- `discussions` (for co-participation)

## Implementation Sketch

```sql
-- Review relationships: who reviews whose MRs
SELECT
    mr.author_username as author,
    n.author_username as reviewer,
    COUNT(*) as review_count
FROM merge_requests mr
JOIN discussions d ON d.merge_request_id = mr.id
JOIN notes n ON n.discussion_id = d.id
WHERE n.note_type = 'DiffNote'
  AND n.is_system = 0
  AND n.author_username != mr.author_username
  AND mr.created_at >= ?1
GROUP BY mr.author_username, n.author_username;

-- Co-participation: who comments on the same entities
WITH entity_participants AS (
    SELECT
        COALESCE(d.issue_id, d.merge_request_id) as entity_id,
        d.noteable_type,
        n.author_username
    FROM discussions d
    JOIN notes n ON n.discussion_id = d.id
    WHERE n.is_system = 0
      AND n.created_at >= ?1
)
SELECT
    a.author_username as person_a,
    b.author_username as person_b,
    COUNT(DISTINCT a.entity_id) as shared_entities
FROM entity_participants a
JOIN entity_participants b
    ON a.entity_id = b.entity_id
    AND a.noteable_type = b.noteable_type
    AND a.author_username < b.author_username  -- avoid duplicates
GROUP BY a.author_username, b.author_username;
```

## Output Formats

### JSON (for further analysis)
```json
{
  "nodes": ["alice", "bob", "charlie"],
  "edges": [
    { "source": "alice", "target": "bob", "reviews": 15, "co_participated": 8 },
    { "source": "bob", "target": "charlie", "reviews": 3, "co_participated": 12 }
  ]
}
```

### Human
```
Collaboration Network (last 90 days)

  alice <-> bob         15 reviews, 8 shared discussions    [strong]
  bob <-> charlie        3 reviews, 12 shared discussions   [moderate]
  alice <-> charlie      1 review, 2 shared discussions     [weak]
  dave <-> (none)        0 reviews, 0 shared discussions    [isolated]
```

## Downsides

- Interpretation requires context; high collaboration might mean dependency
- Doesn't capture collaboration outside GitLab
- Self-join can be slow with many notes

## Extensions

- `lore collaboration --format dot` — GraphViz network diagram
- `lore collaboration --isolated` — find team members with no collaboration edges
- Team boundary detection via graph clustering algorithms
