Skip to content

The agent that grows with you

fix(agent): resolve bare `cd backend` targets in SubdirectoryHintTracker

Trevin Chow7d61b4872ad5
diff --git a/agent/subdirectory_hints.py b/agent/subdirectory_hints.py
index 02fd80a37be..e11272bd363 100644
--- a/agent/subdirectory_hints.py
+++ b/agent/subdirectory_hints.py
@@ -52,6 +52,10 @@ def _first_hint_file(directory: Path):
return None
+_NAV_COMMANDS = frozenset({"cd", "pushd"})
+_SHELL_OPERATORS = frozenset({"&&", "||", "|", ";", "&"})
+
+
class SubdirectoryHintTracker:
"""Track which directories the agent visits and load hints on first access.
@@ -122,6 +126,14 @@ class SubdirectoryHintTracker:
tokens = shlex.split(cmd)
except ValueError:
tokens = cmd.split()
+ # `cd backend && ls`: a bare directory name has no `/` or `.`, so the generic filter below drops
+ # it; the token after a navigation command is a path by construction (#11032). `cd -` / bare `cd`
+ # are skipped (nothing under the working dir to load).
+ for idx, token in enumerate(tokens):
+ if token in _NAV_COMMANDS:
+ target = next((t for t in tokens[idx + 1:] if not t.startswith("-")), None)
+ if target and target not in _SHELL_OPERATORS:
+ self._add_path_candidate(target.rstrip(";"), candidates)
for token in tokens:
if token.startswith(("-", "http://", "https://", "git@")) or ("/" not in token and "." not in token):
continue
diff --git a/tests/agent/test_subdirectory_hints.py b/tests/agent/test_subdirectory_hints.py
index 1277adc8955..78a8cdb5628 100644
--- a/tests/agent/test_subdirectory_hints.py
+++ b/tests/agent/test_subdirectory_hints.py
@@ -78,6 +78,13 @@ class TestSubdirectoryHintTracker:
+ @pytest.mark.parametrize("command", ["cd backend && ls", "pushd backend", "echo start; cd backend; ls"])
+ def test_bare_directory_after_navigation_command_is_a_path(self, project, command):
+ """`cd backend` has no `/` or `.` yet names a subdirectory; its AGENTS.md must load (#11032)."""
+ tracker = SubdirectoryHintTracker(working_dir=str(project))
+ result = tracker.check_tool_call("terminal", {"command": command})
+ assert result is not None and "Backend-specific instructions" in result
+
def test_relative_path(self, project):
"""Relative paths resolved against working_dir."""
tracker = SubdirectoryHintTracker(working_dir=str(project))