fix: apply compilation.exclude patterns during primitive discovery#476
fix: apply compilation.exclude patterns during primitive discovery#476Coolomina wants to merge 1 commit intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a compilation pipeline bug by applying compilation.exclude patterns during primitive discovery, preventing .instructions.md files inside excluded directories from being discovered and included in compiled outputs.
Changes:
- Extend primitive discovery APIs to accept
exclude_patternsand filter discovered files accordingly. - Pass
CompilationConfig.excludefromAgentsCompilerinto discovery (local-only and dependency-aware paths). - Update a unit test mock assertion to reflect the new discovery call signature.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/apm_cli/primitives/discovery.py |
Adds exclude-aware filtering during discovery via a new helper and updated function signatures. |
src/apm_cli/compilation/agents_compiler.py |
Propagates config.exclude into discovery calls. |
tests/unit/compilation/test_agents_compiler_coverage.py |
Updates mocked discovery assertion for the new parameter. |
src/apm_cli/primitives/discovery.py
Outdated
| # "docs/**" style — match anything under the directory | ||
| if normalized.endswith('/**'): | ||
| prefix = normalized[:-3] | ||
| if rel_path_str.startswith(prefix + '/') or rel_path_str == prefix: | ||
| return True | ||
| # "**/test-fixtures/**" style — match directory at any depth | ||
| elif normalized.startswith('**/') and normalized.endswith('/**'): |
There was a problem hiding this comment.
Non-ASCII characters were added in comments (e.g., the em dash in "style — match"). This violates the project's printable-ASCII-only encoding rule for source files and can break Windows cp1252 terminals. Replace these with plain ASCII (e.g., "-" or "--").
| ) as mock_disc: | ||
| result = compiler.compile(config) # no primitives passed → discovers | ||
|
|
||
| mock_disc.assert_called_once_with(str(compiler.base_dir)) | ||
| mock_disc.assert_called_once_with( | ||
| str(compiler.base_dir), exclude_patterns=config.exclude |
There was a problem hiding this comment.
Non-ASCII character in comment (the right arrow in "no primitives passed -> discovers") violates the printable-ASCII-only rule for source files/tests and can cause Windows cp1252 encoding failures. Replace it with ASCII (e.g., "->").
f163986 to
9ab7408
Compare
Propagate exclude patterns from apm.yml to the primitive discovery phase. Previously, patterns were only applied during context optimization, allowing files in excluded directories to leak into compiled output. Add exclude_patterns parameter to discover_primitives(), discover_primitives_with_dependencies(), and scan_local_primitives(). Add _matches_exclude_patterns() helper supporting dir/**, **/dir/**, and fnmatch-style glob patterns. Fixes microsoft#475 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9ab7408 to
d1f1abf
Compare
| return False | ||
|
|
||
|
|
||
| def _match_glob_recursive(path_parts: list, pattern_parts: list) -> bool: |
There was a problem hiding this comment.
Dupped, I know, but extracting it and refactor the code felt out of the scope of this bug.
|
@danielmeppiel Closing this in favor of #477 |
Description
Propagate
compilation.excludepatterns to the primitive discovery phase so that.instructions.mdfiles inside excluded directories are filtered out before compilation.Previously, exclude patterns were only applied during context optimization (directory scanning and placement), but not during discovery. This caused files in excluded directories (e.g.,
docs/**) to leak into compiledAGENTS.mdandCLAUDE.mdoutput.Fixes #475
Type of change
Testing
Changes
discovery.py: Addexclude_patternsparameter todiscover_primitives(),discover_primitives_with_dependencies(), andscan_local_primitives(). Add_matches_exclude_patterns()helper that supportsdir/**,**/dir/**, and fnmatch-style glob patterns.agents_compiler.py: Passconfig.excludeto discovery functions.test_agents_compiler_coverage.py: Update mock assertion to match new call signature.Verification
Unit tests: 3084 passed (0 failures).