fix(agent): scope subdirectory hint discovery to workspace - closes #14471 - #14510
fix(agent): scope subdirectory hint discovery to workspace - closes #14471#14510vominh1919 wants to merge 1 commit into
Conversation
SubdirectoryHintTracker._is_valid_subdir() did not check whether the candidate directory is inside the configured working_dir. This allowed tool calls that touch files in unrelated directories to inject AGENTS.md, CLAUDE.md, or .cursorrules content from completely different projects into the agent context, causing instruction contamination. Add a workspace boundary check using Path.relative_to() so only directories inside working_dir are scanned for hint files. Fixes NousResearch#14471
|
Thanks for the careful diagnosis and the clean fix, @vominh1919 — you nailed both the root cause and the right direction. This is already fixed on Issue #14471 is closed for the same reason. Closing this as redundant — your analysis was spot-on. Thanks for contributing! |
Fix: Scope subdirectory hint discovery to workspace directory
Bug
Closes #14471
Hermes has a second project-context injection path beyond the normal startup cwd-based prompt assembly. Post-tool-call path discovery can append context from nearby AGENTS.md, CLAUDE.md, or .cursorrules files based on tool arguments — even from directories completely outside the intended workspace.
This breaks workspace isolation expectations and can cause:
Root Cause
In
agent/subdirectory_hints.py,SubdirectoryHintTracker._is_valid_subdir()only checks:It does not check whether the directory is inside the configured
working_dir. This means any tool call that touches a file in an unrelated directory can trigger hint discovery there.Fix
Add a workspace boundary check in
_is_valid_subdir()usingPath.relative_to(). Only directories insideworking_dirare scanned for hint files:Impact