Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(decisions): discover numbered ADR folders at arbitrary directory depths (#3061)

Rishabh Mishra7e4b03695dc2
diff --git a/packages/core/src/repowise/core/analysis/decisions/adr.py b/packages/core/src/repowise/core/analysis/decisions/adr.py
index 4135b6938..7a83f9481 100644
--- a/packages/core/src/repowise/core/analysis/decisions/adr.py
+++ b/packages/core/src/repowise/core/analysis/decisions/adr.py
@@ -10,10 +10,9 @@ from repowise.core.ingestion.traverser import load_gitignore_spec
from .source_files import _SKIP_DIRS
-# Conventional ADR homes, as repo-root-relative posix directories. Every ``.md``
-# directly inside one is a candidate regardless of filename; matching is on the
-# whole relative dir, so a stray ``vendor/x/adr/`` does not qualify.
-_ADR_DIRS = frozenset(
+# Conventional ADR homes at the repo root. Every ``.md`` directly inside one
+# is a candidate regardless of filename.
+_CONVENTIONAL_ROOT_DIRS = frozenset(
{
"adr",
"adrs",
@@ -25,8 +24,34 @@ _ADR_DIRS = frozenset(
"doc/adr",
}
)
+# Nested ADR homes recognized at arbitrary directory depths. Deliberately
+# excludes "architecture" (#3057) to avoid sweeping up general design notes
+# in package subdirectories.
+_ADR_DIR_NAMES = frozenset({"adr", "adrs", "decisions"})
+_ADR_SUFFIXES = frozenset(
+ {
+ "doc/adr",
+ "docs/adr",
+ "doc/adrs",
+ "docs/adrs",
+ "doc/decisions",
+ "docs/decisions",
+ }
+)
_MAX_ADR_FILES = 60
+
+def _is_adr_dir(rel_dir: str) -> bool:
+ """Return True if rel_dir is a recognized ADR directory."""
+ if not rel_dir:
+ return False
+ if rel_dir in _CONVENTIONAL_ROOT_DIRS:
+ return True
+ parts = rel_dir.lower().split("/")
+ return parts[-1] in _ADR_DIR_NAMES or (
+ len(parts) >= 2 and f"{parts[-2]}/{parts[-1]}" in _ADR_SUFFIXES
+ )
+
# Nygard/MADR section headings. Mapped to the ExtractedDecision fields they
# populate during the deterministic (LLM-free) parse.
_ADR_HEADING_RE = re.compile(r"^#{1,6}\s+(.+?)\s*$")
@@ -47,9 +72,9 @@ def find_adr_files(repo_path: Path) -> list[Path]:
"""Collect candidate ADR files from the conventional dirs + name match.
One :func:`walk_repo` pass answers both halves: files directly under a
- conventional ADR directory (root-anchored, as the old shallow globs
- were) rank ahead of loose ``*adr*.md`` name matches, and the cap is
- applied to the two buckets in that order.
+ conventional ADR directory (root-anchored or nested) rank ahead of loose
+ ``*adr*.md`` name matches, and the cap is applied to the two buckets in
+ that order.
Ignored paths are excluded. :mod:`repowise.core.fs_walk` prunes junk
dirs and nested repos but deliberately reads no ignore files, so
@@ -72,7 +97,7 @@ def find_adr_files(repo_path: Path) -> list[Path]:
and not ignore.match_file(f"{rel_dir}/{d}/" if rel_dir else f"{d}/")
]
- in_adr_dir = rel_dir in _ADR_DIRS
+ in_adr_dir = _is_adr_dir(rel_dir)
for fname in filenames:
bucket = _adr_bucket(fname, in_adr_dir, conventional, loose)
if bucket is None:
diff --git a/tests/unit/analysis/test_decision_sources.py b/tests/unit/analysis/test_decision_sources.py
index 702012ce2..0663f3b11 100644
--- a/tests/unit/analysis/test_decision_sources.py
+++ b/tests/unit/analysis/test_decision_sources.py
@@ -97,6 +97,34 @@ async def test_discover_adrs_maps_superseded_status_from_frontmatter(tmp_path):
assert "Adopt gRPC" in d.decision
+async def test_discover_adrs_in_nested_directories(tmp_path):
+ breeze_adr = tmp_path / "dev" / "breeze" / "doc" / "adr"
+ breeze_adr.mkdir(parents=True)
+ (breeze_adr / "0001-record-architecture-decisions.md").write_text(_NYGARD_ADR, encoding="utf-8")
+
+ sdk_adr = tmp_path / "go-sdk" / "adr"
+ sdk_adr.mkdir(parents=True)
+ (sdk_adr / "0002-use-grpc.md").write_text(_MADR_ADR, encoding="utf-8")
+
+ ex = DecisionExtractor(repo_path=tmp_path)
+ decisions = await ex.discover_adrs()
+
+ assert len(decisions) == 2
+ titles = {d.title for d in decisions}
+ assert "1. Use PostgreSQL for primary storage" in titles
+ assert "Adopt gRPC for service-to-service calls" in titles
+
+
+async def test_nested_architecture_notes_folder_is_not_treated_as_adr(tmp_path):
+ arch_dir = tmp_path / "packages" / "core" / "architecture"
+ arch_dir.mkdir(parents=True)
+ (arch_dir / "overview.md").write_text("# Overview\n\nSome notes.\n", encoding="utf-8")
+
+ ex = DecisionExtractor(repo_path=tmp_path)
+ decisions = await ex.discover_adrs()
+
+ assert decisions == []
+
def test_conventional_adrs_win_the_cap_over_earlier_loose_matches(tmp_path, monkeypatch):
"""Loose name matches walked first must not fill the cap before an ADR dir."""
@@ -178,6 +206,17 @@ class TestAdrDiscoveryHonorsIgnoreFiles:
assert len(decisions) == 1
assert "Use PostgreSQL" in decisions[0].title
+ async def test_nested_adr_in_ignored_folder_is_skipped(self, tmp_path):
+ """Ignored nested ADR directory tree must not contribute records."""
+ (tmp_path / ".gitignore").write_text("dev/breeze/\n", encoding="utf-8")
+ breeze_adr = tmp_path / "dev" / "breeze" / "doc" / "adr"
+ breeze_adr.mkdir(parents=True)
+ (breeze_adr / "0001-record-architecture-decisions.md").write_text(_NYGARD_ADR, encoding="utf-8")
+
+ decisions = await DecisionExtractor(repo_path=tmp_path).discover_adrs()
+
+ assert decisions == []
+
async def test_extract_all_runs_deterministic_sources_and_gates(tmp_path):
adr_dir = tmp_path / "docs" / "adr"