-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Describe the bug
The default directory exclusion logic in _analyze_project_structure() uses substring matching (ignore in str(current_path)) to check if a path should be excluded. This can produce false positives when a directory name contains an exclusion token as a substring.
Examples of false positives:
docs/apm_modules_guide/would be excluded becauseapm_modulesis a substring of the pathsrc/rebuild/would be excluded becausebuildis a substring ofrebuildtools/node_modules_compat/would be excluded becausenode_modulesis a substringlib/redistribution/would be excluded becausedistis a substring ofredistribution
Affected code:
# context_optimizer.py, _analyze_project_structure()
if any(ignore in str(current_path) for ignore in DEFAULT_EXCLUDED_DIRNAMES):
continueTo Reproduce
- Create a project with a directory whose name contains (but does not equal) an exclusion token, e.g.
docs/apm_modules_guide/ - Place an
.instructions.mdfile inside that directory - Run
apm compile --verbose - The instruction is silently ignored because the directory is incorrectly excluded
Expected behavior
Only directories whose path components exactly match an exclusion name should be excluded. A path like docs/apm_modules_guide/ should not be excluded just because it contains apm_modules as a substring.
Suggested fix:
Replace substring matching with path-component matching:
relative_parts = current_path.relative_to(self.base_dir).parts
if any(part in DEFAULT_EXCLUDED_DIRNAMES for part in relative_parts):
continueEnvironment:
- OS: macOS / Linux / Windows (all affected)
- APM Version: 0.7.4+
- Affected since: pre-existing (before [BUG] Compilation extremely slow on projects with apm_modules dependencies #154, but [BUG] Compilation extremely slow on projects with apm_modules dependencies #154 expanded the exclusion list making false positives more likely)
Additional context
Discovered during Copilot code review on PR #157. This is a pre-existing pattern, not introduced by the performance fix, but the addition of apm_modules to the default exclusion list increases the surface area for false positives. The _should_exclude_subdir() method already uses exact component matching (path.name in ...) which is correct — only _analyze_project_structure() uses the problematic substring approach.