# Ownership and knowledge risk

See who owns each file and module, each file's bus factor, where knowledge is at risk, and who should review a change, all from git history.

Repowise reads git history to tell you who owns each file and module, how many
people it would take to lose the knowledge behind a file (its bus factor), and
where that knowledge is already at risk: a file still being edited whose main
author has gone quiet, a file with many drive-by authors and no clear owner, or
a busy file with too many hands on it. It also suggests reviewers for a set of
changed files.

Everything is computed from `git log` (and `git blame` in the standard index)
during `repowise init` and `repowise update`, with no model key and no network
calls. "Owner" means the person who wrote the most commits or lines.

## Quick start

Ownership is computed during indexing. Read it for one file:

```bash
repowise context src/auth/session.py --include ownership
repowise risk --target src/auth/session.py     # owner, recent owner, bus factor
repowise health --file src/auth/session.py     # knowledge_loss and related findings
```

From an agent:

```python
get_context(targets=["src/auth/session.py"], include=["ownership"])
get_risk(targets=["src/auth/session.py"])
get_risk(changed_files=["src/api/routes.ts", "src/middleware/cors.ts"])
get_overview(include=["ownership"])
```

You should see an ownership block like this on the file's card:

```json
"ownership": {
  "primary_owner": "Dana Lee",
  "owner_pct": 0.71,
  "owner_line_pct": 0.83,
  "contributor_count": 4,
  "bus_factor": 1,
  "recent_owner": "Sam Ortiz",
  "recent_owner_pct": 0.6
}
```

In the dashboard, open **Owners** for the contributor directory and per-person
profiles, and the **Impact** tab of **Code Health** for reviewer suggestions on a
set of files.

Ownership reads the history the index has. In a shallow clone, run
`git fetch --unshallow` before indexing so owners and bus factors cover the
full history.

## Per-file fields

| Field | Meaning |
|---|---|
| `primary_owner` | The file's owner. In the standard index this is the author of the most surviving lines by `git blame`; in a fast index (`--mode fast`, no blame) it is the author of the most commits |
| `owner_pct` | The primary owner's share of the file's commits (0 to 1). Empty when the blame owner made none of the indexed commits |
| `owner_line_pct` | The primary owner's share of current lines by blame (0 to 1). Empty without blame |
| `recent_owner`, `recent_owner_pct` | Who made the most commits to the file in the last 90 days, and their share of those commits. `get_context` shows these when the recent owner differs from the primary owner |
| `contributor_count` | Distinct authors in the indexed history of the file |
| `bus_factor` | How many of the top authors it takes to cover 80% of the file's commits. 1 means one person wrote at least 80% of them. 0 means no history was indexed for the file |

Commits that only move a file do not count as authoring it. Author names and
emails go through the repository's `.mailmap`, and GitHub `noreply` addresses
for one login fold into one person, so a contributor who committed from several
addresses counts once. Each file keeps its top 50 authors.

A commit a coding agent authored counts for the person behind it: the human
its first `Co-authored-by` trailer names, else a human committer. With no human
signal the commit stays the agent's and shows as an agent. Bots own nothing.

## Modules, silos and the knowledge matrix

Per module (top-level directory), the owner is the person who is primary owner
of the most files in it. A module is a **silo** when one person owns more than
80% of its files. Per file, the dashboard and REST API mark a silo when the
primary owner holds more than 80% of the file's commits.

| Number | Where | Meaning |
|---|---|---|
| Truck factor | Stats page | Fewest primary owners who together own more than half the owned files. Bot authors are left out |
| Single-owner files | Stats page | Files with bus factor 1 |
| Silo count | Stats page | Modules where one person owns more than 80% of files |
| `knowledge_map.top_owners` | `get_overview(include=["ownership"])` | The three people owning the most files, by display name only |

The REST API serves two more views. `/api/repos/<id>/owners/summary` returns
the truck factor, single-owner files, silo modules, the share of owned files
held by the top three people, active contributors, and quiet owners (no commit
in 90 days, still owning files that changed in that window).
`/api/repos/<id>/owners/knowledge-matrix` returns every code file's top five
people with their share of its commits, for off-boarding what-ifs. Both count
people only: each contributor carries a `kind` (`human`, `bot`, `agent`), and
bots and agents hold no share.

Each person in **Owners** has a profile: files and hotspots they own, modules
where they hold more than 80% of files, files they own with bus factor 1, dead
code in files they own, commits in the 90 days before the newest commit, and
the people they share files with most.

## Detectors

Three [code health](https://docs.repowise.dev/intelligence/code-health) detectors turn these fields
into findings, listed with the rest of the health findings.

| Detector | Fires when | Severity |
|---|---|---|
| `knowledge_loss` | The file is still changing (a commit in 90 days, or a hotspot; never a file marked stable), its bus factor is 1, and the primary owner is not the recent owner or the recent owner makes under 20% of recent commits | High on a hotspot; medium when both conditions hold; otherwise low |
| `ownership_risk` | The file has 5 or more commits and either 3 or more minor contributors (each under 5% of commits) or no author above 40% | Critical at 6+ minor contributors on a hotspot; high at 5+, or 3+ on a hotspot; medium at 3+; otherwise low. Low on a file under 40 code lines |
| `developer_congestion` | 5 or more contributors, at least 3 commits in the last 90 days, the file is in the top quarter of churn for this repository, and nobody holds half the commits | High at 10+ contributors and 20+ commits in 90 days; medium at 7+ contributors or 12+ commits; otherwise low |

A stable file whose author left never fires `knowledge_loss`: the finding
matters while people are editing around the lost author's intent.

On a small team (3 or fewer active contributors in 90 days), one owner per file
is the normal way of working. `knowledge_loss` and `ownership_risk` cap the
finding at low severity there unless the file is a hotspot, and add
"informational: small team" to the reason.

In the health score's defect calibration, `ownership_risk` carries a higher
weight than the default and is one of the strongest predictors. All three share
the change-history category cap.

## Reviewer suggestions

Two surfaces suggest reviewers for a set of changed files:

- **Dashboard and REST** (`/api/repos/<id>/reviewer-suggestions`): each author of
  a touched file scores their share of its commits, plus a recency term from the
  file's 90-day activity. Authors of each touched file's five strongest
  co-change partners score at half weight. Each suggestion lists the files it
  owns and the co-change files behind it.
- **`get_risk(changed_files=...)`**: `directive.recommended_reviewers` lists
  up to five primary owners of the affected files, ranked by how many of those
  files they own, then by average ownership share. From the CLI:
  `repowise risk --target <file> --changed-file <file> --format json`.

## Tuning

The detectors read the code-health rules file, `.repowise/health-rules.json`:

```json
{
  "profile": "small-team",
  "disabled_biomarkers": ["developer_congestion"],
  "rules": [
    { "path": "vendor/**", "disabled_biomarkers": ["ownership_risk", "knowledge_loss"] }
  ]
}
```

- The `small-team` profile lowers all three detectors (and a few process
  signals) to low severity.
- `severity_overrides` sets a detector's label; an explicit entry wins over the
  profile.

Indexing flags that shape ownership (all saved to config):

| Command | Flag | Effect |
|---|---|---|
| `repowise init` | `--commit-limit N` | Newest commits read for file history (default 5,000; set it above the commit count for full history) |
| `repowise init` | `--follow-renames` | Follow a file across renames, so ownership survives a move |
| `repowise init` | `--mode fast` | Skip blame; owners come from commit counts and `owner_line_pct` stays empty |

The full rules schema is on
[Configuration](https://docs.repowise.dev/installation/config-reference#the-health-rulesjson-file).

## Where it shows up

| Surface | What you get |
|---|---|
| CLI | `repowise context --include ownership`, `repowise risk --target` (owner, recent owner, bus factor), `repowise health` findings |
| MCP | [`get_context`](https://docs.repowise.dev/mcp/get-context) `ownership` block, [`get_risk`](https://docs.repowise.dev/mcp/get-risk) owner fields and PR-mode reviewers, [`get_overview`](https://docs.repowise.dev/mcp/get-overview) ownership summary, [`get_health`](https://docs.repowise.dev/mcp/get-health) findings |
| Dashboard | **Owners** directory and profiles, **Stats** people numbers, **Code Health** findings and **Impact** reviewer suggestions |
| Editor | VS Code: file hover shows the owner and their commit share; the **Hotspots & Ownership** view lists module owners and flags silos, with bus factor in each hotspot's tooltip |

## Next

- [Git history](https://docs.repowise.dev/intelligence/git-history) hotspots and co-change pairs from the same history.
- [Components](https://docs.repowise.dev/intelligence/components) declared owners checked against recent activity.
- [Code health](https://docs.repowise.dev/intelligence/code-health) how the ownership detectors feed the score.
- [Change risk](https://docs.repowise.dev/intelligence/change-risk) review a diff with its history.
