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(augment): preserve leading dot for dot-directory paths in decision_inject and glob_rescue (#4027)

Abdullah Azmid0f3b853da0a
diff --git a/packages/cli/src/repowise/cli/commands/augment_cmd/decision_inject.py b/packages/cli/src/repowise/cli/commands/augment_cmd/decision_inject.py
index 0a8a3baab..a3b3e53bc 100644
--- a/packages/cli/src/repowise/cli/commands/augment_cmd/decision_inject.py
+++ b/packages/cli/src/repowise/cli/commands/augment_cmd/decision_inject.py
@@ -257,7 +257,7 @@ def _collect_seeds(repo_path: Path) -> tuple[list[str], str]:
dirty, branch = _dirty_files_and_branch(repo_path)
seen: dict[str, None] = {}
for f in dirty + _branch_changed_files(repo_path, branch) + _previous_session_edits(repo_path):
- norm = f.replace("\\", "/").lstrip("./")
+ norm = f.replace("\\", "/").removeprefix("./")
if norm:
seen.setdefault(norm, None)
return list(seen)[:_MAX_SEEDS], branch
diff --git a/packages/cli/src/repowise/cli/commands/augment_cmd/glob_rescue.py b/packages/cli/src/repowise/cli/commands/augment_cmd/glob_rescue.py
index 8fa038c0a..d03de8e03 100644
--- a/packages/cli/src/repowise/cli/commands/augment_cmd/glob_rescue.py
+++ b/packages/cli/src/repowise/cli/commands/augment_cmd/glob_rescue.py
@@ -92,13 +92,30 @@ def _translate(pattern: str) -> re.Pattern[str] | None:
return None
+def _normalize_pattern(repo_path: Path, pattern: str) -> str:
+ """Convert *pattern* to a repo-relative POSIX glob while keeping dot-directories."""
+ norm = pattern.replace("\\", "/")
+ try:
+ roots = (str(repo_path), str(repo_path.resolve()))
+ except OSError:
+ roots = (str(repo_path),)
+ for root in roots:
+ prefix = root.replace("\\", "/").rstrip("/")
+ if prefix and norm.startswith(prefix + "/"):
+ norm = norm[len(prefix) + 1 :]
+ break
+ while norm.startswith("./"):
+ norm = norm[2:]
+ return norm.lstrip("/")
+
+
def matching_paths(repo_path: Path, pattern: str, limit: int = _MAX_LISTED) -> tuple[list[str], int]:
"""``(paths, total)`` indexed under *repo_path* matching *pattern*.
``total`` is the full match count, so the caller can say how many it is
not showing. Any failure answers ``([], 0)`` — silence, never a guess.
"""
- matcher = _translate(pattern.replace("\\", "/").lstrip("./"))
+ matcher = _translate(_normalize_pattern(repo_path, pattern))
if matcher is None:
return [], 0
from . import fast_lookup
diff --git a/tests/unit/cli/test_augment_decision_inject.py b/tests/unit/cli/test_augment_decision_inject.py
index 9cdc2562b..dd1640f18 100644
--- a/tests/unit/cli/test_augment_decision_inject.py
+++ b/tests/unit/cli/test_augment_decision_inject.py
@@ -150,6 +150,28 @@ async def test_seed_linked_decision_injected(tmp_path, monkeypatch):
assert "Batch the embed calls" not in block
+async def test_dot_directory_seed_preserves_leading_dot_and_strips_dot_slash(
+ tmp_path, monkeypatch
+):
+ ci_decision = {
+ "id": "d-ci",
+ "title": "Pin CI actions by SHA",
+ "decision": "Every GitHub Actions workflow pins actions by full commit SHA",
+ "links": [(".github/workflows/ci.yml", "file")],
+ }
+ await _build_wiki_db(tmp_path, [ci_decision, _AUTH_DECISION])
+
+ _quiet_git(monkeypatch, dirty=[".github/workflows/ci.yml"])
+ block = decision_inject._session_decision_block(tmp_path, "sess-dot")
+ assert block is not None
+ assert "Pin CI actions by SHA" in block
+
+ _quiet_git(monkeypatch, dirty=["./src/core/auth.py"])
+ block_rel = decision_inject._session_decision_block(tmp_path, "sess-rel")
+ assert block_rel is not None
+ assert "Use JWT auth" in block_rel
+
+
async def test_silence_when_nothing_relevant(tmp_path, monkeypatch):
await _build_wiki_db(tmp_path, [_UNRELATED_DECISION])
_quiet_git(monkeypatch, dirty=["src/core/auth.py"])
diff --git a/tests/unit/cli/test_augment_wrong_path.py b/tests/unit/cli/test_augment_wrong_path.py
index 774164e7f..34544053c 100644
--- a/tests/unit/cli/test_augment_wrong_path.py
+++ b/tests/unit/cli/test_augment_wrong_path.py
@@ -159,10 +159,22 @@ def test_a_relative_escape_to_another_checkout_stays_silent(tmp_path: Path) -> N
def test_a_dot_directory_keeps_its_dot(tmp_path: Path) -> None:
"""".github/ci.yml" must not be echoed back as "github/ci.yml"."""
+ from repowise.cli.commands.augment_cmd import glob_rescue
+
repo = _repo(tmp_path, (".github/workflows/ci.yml",))
result = _fire(repo, ".github/ci.yml")
assert result.context is not None
assert result.context.startswith("[repowise] .github/ci.yml is not in this tree.")
+ for pattern in (
+ ".github/workflows/*.yml",
+ "./.github/workflows/*.yml",
+ "/.github/workflows/*.yml",
+ str(repo / ".github" / "workflows" / "*.yml"),
+ ):
+ assert glob_rescue.matching_paths(repo, pattern) == (
+ [".github/workflows/ci.yml"],
+ 1,
+ )
def test_a_repo_under_a_path_with_spaces_still_rescues(tmp_path: Path) -> None: