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(code-origin): narrow the tools/ path rule to repo-root and build-tool contexts (#4652)

Raghav Chamadiya3b8b8783db49
diff --git a/packages/core/src/repowise/core/code_origin.py b/packages/core/src/repowise/core/code_origin.py
index 6512dd696..381cec552 100644
--- a/packages/core/src/repowise/core/code_origin.py
+++ b/packages/core/src/repowise/core/code_origin.py
@@ -784,11 +784,19 @@ def is_migration_path(path: str) -> bool:
# folder), not developer tooling.
_SERVED_DIRS = frozenset({"static", "public", "assets", "_static"})
_SERVED_SCRIPTS_DIR = "scripts"
+# ``tools/`` is developer tooling at the repository root or under an engineering
+# folder (``eng/tools``, ``hack/tools``). Deeper it is as often the product's own
+# code: AI SDK tools in ``lib/ai/tools``, ``src/tools``, ``pkg/tools``. Ceiling:
+# path-only, so a monorepo member's own ``tools/`` reads as production.
+_TOOLS_DIR = "tools"
+_TOOLS_PARENT_DIRS = frozenset({"eng", "hack", "ci", "dev"})
def _is_tooling_dir(i: int, d: str, dirs: list[str]) -> bool:
if d not in _TOOLING_DIR_TOKENS:
return False
+ if d == _TOOLS_DIR:
+ return i == 0 or dirs[i - 1] in _TOOLS_PARENT_DIRS
return d != _SERVED_SCRIPTS_DIR or _SERVED_DIRS.isdisjoint(dirs[:i])
diff --git a/packages/core/src/repowise/core/workspace/diagnostics.py b/packages/core/src/repowise/core/workspace/diagnostics.py
index 56eb68fb0..7c978c05b 100644
--- a/packages/core/src/repowise/core/workspace/diagnostics.py
+++ b/packages/core/src/repowise/core/workspace/diagnostics.py
@@ -733,9 +733,9 @@ def _runtime_contracts(
A script polling a dev server is not a call of the running system, so it is
left out of every count here, as the network probe leaves those files out
of its own. One that linked stays: the link shows it reaches a service.
- Ceiling: the origin is path-only, so a product folder named ``tools/`` or
- ``scripts/`` reads as tooling too; a classifier that reads the package
- layout would narrow it, and it belongs in ``code_origin`` when it comes.
+ Ceiling: the origin is path-only, so a product folder named ``scripts/``
+ reads as tooling too; a classifier that reads the package layout would
+ narrow it, and it belongs in ``code_origin`` when it comes.
"""
return [
c
diff --git a/tests/unit/test_code_origin.py b/tests/unit/test_code_origin.py
index 62e2702a8..73616bca2 100644
--- a/tests/unit/test_code_origin.py
+++ b/tests/unit/test_code_origin.py
@@ -83,6 +83,17 @@ _OWN_HEADER = (
("public/scripts/app.js", "production"),
("scripts/public/seed.py", "tooling"),
("tools/gen.go", "tooling"),
+ ("eng/tools/gen.cs", "tooling"),
+ ("hack/tools/main.go", "tooling"),
+ ("ci/tools/lint.py", "tooling"),
+ ("Tools/Gen/Program.cs", "tooling"),
+ ("build/tools/gen.py", "tooling"),
+ # A ``tools/`` folder inside the product is its own code.
+ ("lib/ai/tools/get-weather.ts", "production"),
+ ("src/tools/search.py", "production"),
+ ("pkg/tools/client.go", "production"),
+ ("src/main/java/com/x/tools/HttpUtil.java", "production"),
+ ("modal_app/security/tools/gitleaks.py", "production"),
# Dart's ``tool/`` (flutter samples' CI scripts), but not a shipped one.
("tool/ci_script.dart", "tooling"),
("desktop_photo_search/material/tool/grind.dart", "tooling"),