Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
feat(identity): tell people, coding agents and bots apart (#2754)
Raghav Chamadiya1d0f4ece12a1
diff --git a/packages/core/src/repowise/core/author_identity.py b/packages/core/src/repowise/core/author_identity.pyindex a7bfde92c..8ca971636 100644--- a/packages/core/src/repowise/core/author_identity.py+++ b/packages/core/src/repowise/core/author_identity.py@@ -23,6 +23,10 @@ from __future__ import annotationsimport refrom collections import Counter, defaultdictfrom collections.abc import Iterable+from functools import lru_cache+from typing import Literal++IdentityKind = Literal["human", "agent", "bot"]_NOREPLY_DOMAIN = "@users.noreply.github.com"@@ -98,19 +102,31 @@ def author_identity_key(author_name: str | None, author_email: str | None) -> streturn (canonical or author_name or "").strip().lower()-def is_bot(name: str | None, email: str | None) -> bool:- """True when this author is automation (CI or a coding agent's own identity).+@lru_cache(maxsize=4096)+def _identity(name: str | None, email: str | None) -> tuple[IdentityKind, str | None]:+ """``(kind, agent label)`` for one author observation."""+ # Imported here: the provenance module loads the whole git indexer package.+ from repowise.core.ingestion.git_indexer.agent_provenance import agent_from_identity++ agent = agent_from_identity(name, email)+ if agent:+ return "agent", agent+ if (name and _BOT_NAME_RE.search(name)) or (email and _BOT_EMAIL_RE.search(email)):+ return "bot", None+ return "human", None+++def identity_kind(name: str | None, email: str | None) -> IdentityKind:+ """Who an author identity is: a coding agent, other automation, or a person.Identity only: an agent-*assisted* commit still has a human author."""- # Imported here: the provenance module loads the whole git indexer package.- from repowise.core.ingestion.git_indexer.agent_provenance import agent_from_identity+ return _identity(name, email)[0]- if agent_from_identity(name, email):- return True- if name and _BOT_NAME_RE.search(name):- return True- return bool(email and _BOT_EMAIL_RE.search(email))++def is_bot(name: str | None, email: str | None) -> bool:+ """True when this author is automation (CI or a coding agent's own identity)."""+ return identity_kind(name, email) != "human"def _is_machine_local(canonical_email: str) -> bool:@@ -164,10 +180,18 @@ class IdentityResolver:resolver was not built from resolves to its own canonical email."""- def __init__(self, key_of: dict[str, str], names: dict[str, Counter[str]], bots: set[str]):+ def __init__(+ self,+ key_of: dict[str, str],+ names: dict[str, Counter[str]],+ kinds: dict[str, IdentityKind],+ agents: dict[str, str],+ ):self._key_of = key_ofself._names = names- self._bots = bots+ # Automation identities only; every other key is a person.+ self._kinds = kinds+ self._agents = agentsdef __call__(self, name: str | None, email: str | None) -> str:node = _node(name, email)@@ -182,12 +206,19 @@ class IdentityResolver:# Ties break alphabetically so the name is stable across runs.return min(pool, key=lambda n: (-pool[n], n))+ def kind(self, key: str) -> IdentityKind:+ return self._kinds.get(key, "human")++ def agent_of(self, key: str) -> str | None:+ """The coding agent behind an agent identity, else ``None``."""+ return self._agents.get(key)+def is_bot(self, key: str) -> bool:- return key in self._bots+ return key in self._kindsdef people(self) -> set[str]:"""Every human identity the resolver was built from."""- return set(self._names) - self._bots+ return set(self._names) - set(self._kinds)def build_identity_resolver(@@ -225,22 +256,31 @@ def build_identity_resolver(whose email the author pairs already know."""names: dict[str, Counter[str]] = defaultdict(Counter)- bot_votes: Counter[str] = Counter()- bot_cache: dict[tuple[str | None, str | None], bool] = {}+ kind_votes: dict[str, Counter[str]] = defaultdict(Counter)+ agent_votes: dict[str, Counter[str]] = defaultdict(Counter)+ identity_cache: dict[tuple[str | None, str | None], tuple[IdentityKind, str | None]] = {}logins: dict[str, str] = {}for name, email in pairs:node = _node(name, email)if not node:continuenames[node][_clean_name(name) or node] += 1- if (name, email) not in bot_cache:- bot_cache[(name, email)] = is_bot(name, email)- bot_votes[node] += 1 if bot_cache[(name, email)] else -1+ if (name, email) not in identity_cache:+ identity_cache[(name, email)] = _identity(name, email)+ obs_kind, agent = identity_cache[(name, email)]+ kind_votes[node][obs_kind] += 1+ if agent:+ agent_votes[node][agent] += 1m = _GH_NOREPLY_RE.match((email or "").strip().lower())if m:logins[node] = m.group("login")- # A node is automation when most of its observations say so.- bots = {n for n, v in bot_votes.items() if v > 0}+ # A node is automation when most of its observations say so (a tie stays+ # human); an agent/bot tie goes to the more specific agent.+ auto_kinds: dict[str, IdentityKind] = {}+ for node, votes in kind_votes.items():+ if votes["agent"] + votes["bot"] > votes["human"]:+ auto_kinds[node] = "agent" if votes["agent"] >= votes["bot"] else "bot"+ bots = set(auto_kinds)def kind(node: str) -> str:if node.startswith("name:"):@@ -311,4 +351,9 @@ def build_identity_resolver(merged[key][_clean_name(name)] += 1# Bots never merge, so a bot's identity is its own node.- return IdentityResolver(key_of, merged, bots)+ agents = {+ n: min(agent_votes[n], key=lambda a: (-agent_votes[n][a], a))+ for n, k in auto_kinds.items()+ if k == "agent" and agent_votes[n]+ }+ return IdentityResolver(key_of, merged, auto_kinds, agents)diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py b/packages/core/src/repowise/core/ingestion/git_indexer/_constants.pyindex 52a7db940..6af503da2 100644--- a/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py+++ b/packages/core/src/repowise/core/ingestion/git_indexer/_constants.py@@ -63,7 +63,6 @@ _DECISION_SIGNAL_WORDS: frozenset[str] = frozenset(})-_SKIP_AUTHORS = ("dependabot", "renovate", "github-actions")_MIN_MESSAGE_LEN = 12# Default per-file commit history depth.diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/enrich.py b/packages/core/src/repowise/core/ingestion/git_indexer/enrich.pyindex d70522c77..cb1c81ada 100644--- a/packages/core/src/repowise/core/ingestion/git_indexer/enrich.py+++ b/packages/core/src/repowise/core/ingestion/git_indexer/enrich.py@@ -13,11 +13,12 @@ import jsonfrom collections import Counterfrom typing import Any+from repowise.core.author_identity import identity_kind, is_bot+from ._constants import (_DECISION_SIGNAL_WORDS,_HARD_SKIP_PREFIXES,_MIN_MESSAGE_LEN,- _SKIP_AUTHORS,_SOFT_SKIP_PREFIXES,HOTSPOT_HIGH_COMMITS_90D,HOTSPOT_MIN_COMMITS_90D,@@ -84,7 +85,7 @@ def get_blame_ownership(repo: Any, file_path: str) -> tuple[str | None, str | Noreturn top_name, emails.get(top_name), pct-def is_significant_commit(message: str, author: str) -> bool:+def is_significant_commit(message: str, author: str, email: str | None = None) -> bool:"""Return True if the commit is considered significant.Filtering rules:@@ -103,11 +104,9 @@ def is_significant_commit(message: str, author: str) -> bool:for prefix in _HARD_SKIP_PREFIXES:if msg.startswith(prefix):return False- # Always skip bot authors- author_lower = author.lower()- for skip in _SKIP_AUTHORS:- if skip in author_lower:- return False+ # Always skip bot authors; a coding agent's commit can still carry a decision.+ if identity_kind(author, email) == "bot":+ return False# Soft-skip conventional prefixes unless decision signal presentfor prefix in _SOFT_SKIP_PREFIXES:if msg.startswith(prefix):@@ -153,7 +152,7 @@ def meets_hotspot_floors(meta: dict) -> bool:def count_active_contributors(metadata_list: list[dict], *, window_days: int = 90) -> int | None:- """Count distinct non-bot authors active in the trailing *window_days*.+ """Count distinct human authors active in the trailing *window_days*.Reads each file's ``top_authors_json`` (per-author ``last_commit_ts``)and anchors the window to the most recent author timestamp seen across@@ -184,8 +183,7 @@ def count_active_contributors(metadata_list: list[dict], *, window_days: int = 9name = str(a.get("name") or "").strip()if not name:continue- lowered = name.lower()- if any(skip in lowered for skip in _SKIP_AUTHORS):+ if is_bot(name, a.get("email")):continueprev = author_last_ts.get(name)if prev is None or ts > prev:diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/file_history.py b/packages/core/src/repowise/core/ingestion/git_indexer/file_history.pyindex aac5ec845..91be6cbc0 100644--- a/packages/core/src/repowise/core/ingestion/git_indexer/file_history.py+++ b/packages/core/src/repowise/core/ingestion/git_indexer/file_history.py@@ -586,7 +586,7 @@ def _add_commit_messages(meta: dict[str, Any], commits: list[_CommitRec]) -> Nonsig_commits: list[dict[str, Any]] = []for c in commits:msg = c.subject[:200]- if is_significant_commit(msg, c.author_name):+ if is_significant_commit(msg, c.author_name, c.author_email):sig_commits.append(_significant_entry(c, msg))if len(sig_commits) >= _MAX_SIGNIFICANT_COMMITS:breakdiff --git a/tests/unit/ingestion/test_author_identity.py b/tests/unit/ingestion/test_author_identity.pyindex fea06c032..10ff3a441 100644--- a/tests/unit/ingestion/test_author_identity.py+++ b/tests/unit/ingestion/test_author_identity.py@@ -8,6 +8,7 @@ per-file author-email selection in ``index_file``.from __future__ import annotations+import jsonimport osimport subprocessfrom pathlib import Path@@ -15,10 +16,15 @@ from pathlib import Pathimport gitimport pytest+from repowise.core.author_identity import identity_kind, is_botfrom repowise.core.ingestion.git_indexer import (build_identity_resolver,canonicalize_author_email,)+from repowise.core.ingestion.git_indexer.enrich import (+ count_active_contributors,+ is_significant_commit,+)from repowise.core.ingestion.git_indexer.identity import author_identity_keyfrom repowise.core.ingestion.git_indexer.records import capture_repo_totals, count_peoplefrom repowise.core.stats_highlights import build_people@@ -325,6 +331,89 @@ def test_bots_never_merge_and_are_not_people() -> None:assert resolve.people() == {"[email protected]"}+KIND_CASES = [+ ("copilot-swe-agent[bot]", "[email protected]", "agent"),+ ("devin-ai-integration[bot]", "158243242+devin-ai-integration[bot]@users.noreply.github.com", "agent"),+ ("Cursor Agent", "[email protected]", "agent"),+ ("Claude", "[email protected]", "agent"),+ ("Claude", "", "agent"),+ ("dependabot[bot]", f"49699333+dependabot[bot]{_NR}", "bot"),+ ("github-actions", "[email protected]", "bot"),+ ("renovate", "", "bot"),+ ("Deploy Bot", "[email protected]", "bot"),+ ("Dana White", "[email protected]", "human"),+ # Near misses stay people: no loose substring or first-name rules.+ ("Claudette Moreau", "[email protected]", "human"),+ ("Netlify Johnson", "[email protected]", "human"),+ ("Aiden Coplin", "[email protected]", "human"),+ ("renovate-fan", "[email protected]", "human"),+]++[email protected](("name", "email", "kind"), KIND_CASES)+def test_identity_kind_table(name, email, kind) -> None:+ assert identity_kind(name, email) == kind+ # is_bot keeps meaning "automation of any kind".+ assert is_bot(name, email) is (kind != "human")+++def test_resolver_kinds_and_agent_label() -> None:+ pairs = [+ ("Cursor Agent", "[email protected]"),+ ("dependabot[bot]", f"49699333+dependabot[bot]{_NR}"),+ ("Dana White", "[email protected]"),+ ]+ resolve = build_identity_resolver(pairs)+ agent = resolve("Cursor Agent", "[email protected]")+ bot = resolve("dependabot[bot]", f"49699333+dependabot[bot]{_NR}")+ assert resolve.kind(agent) == "agent"+ assert resolve.agent_of(agent) == "cursor"+ assert resolve.kind(bot) == "bot"+ assert resolve.agent_of(bot) is None+ assert resolve.kind("[email protected]") == "human"+ assert resolve.agent_of("[email protected]") is None+ # An unknown key is a person, as before.+ assert resolve.kind("[email protected]") == "human"+ assert resolve.people() == {"[email protected]"}+ assert resolve.is_bot(agent) and resolve.is_bot(bot)+++def test_kind_vote_ties() -> None:+ # One email seen as a person once and as automation once: a tie stays human.+ shared = "[email protected]"+ resolve = build_identity_resolver([("Ops Team", shared), ("ops-bot", shared)])+ assert resolve.kind(shared) == "human"+ assert not resolve.is_bot(shared)+ # Automation wins a majority, and an agent/bot tie goes to the agent.+ resolve = build_identity_resolver(+ [("Claude", shared), ("ops-bot", shared), ("Claude", shared), ("ops-bot", shared)]+ )+ assert resolve.kind(shared) == "agent"+ assert resolve.agent_of(shared) == "claude"+ resolve = build_identity_resolver([("ops-bot", shared)] * 2 + [("Claude", shared)])+ assert resolve.kind(shared) == "bot"+ assert resolve.agent_of(shared) is None+++def test_significance_skips_bots_but_keeps_agent_commits() -> None:+ msg = "refactor: migrate the cache to a write-through store"+ assert is_significant_commit(msg, "dependabot[bot]") is False+ assert is_significant_commit(msg, "Deploy Bot") is False+ assert is_significant_commit(msg, "Ada Lovelace") is True+ assert is_significant_commit(msg, "Cursor Agent", "[email protected]") is True+++def test_active_contributors_count_people_only() -> None:+ ts = 1_700_000_000+ authors = [+ {"name": "Dana White", "email": "[email protected]", "last_commit_ts": ts},+ {"name": "Cursor Agent", "email": "[email protected]", "last_commit_ts": ts},+ {"name": "github-actions[bot]", "email": "", "last_commit_ts": ts},+ {"name": "Lee Park", "email": "[email protected]", "last_commit_ts": ts - 86400},+ ]+ assert count_active_contributors([{"top_authors_json": json.dumps(authors)}]) == 2++def test_co_author_trailer_alone_never_merges() -> None:# Only a trailer names the real email with the handle, so E4 has no author# row to stand on and the two stay apart. The trailer's name still counts