[fix] include dependency instructions in claude compile (#631)#642
Conversation
sergio-sisternes-epam
left a comment
There was a problem hiding this comment.
Nice fix — this is a real bug and the regression tests are well-targeted. The PR description is excellent too, clear reproduction and rationale.
Two requests before we can merge:
1. Reduce code duplication in scan_directory_with_source
The glob-scan-parse loop is copy-pasted for .apm/ and .github/. Consider extracting a small helper:
def _scan_patterns(base_dir: Path, patterns: Dict[str, List[str]], collection: PrimitiveCollection, source: str) -> None:
for primitive_type, type_patterns in patterns.items():
for pattern in type_patterns:
for file_path_str in glob.glob(str(base_dir / pattern), recursive=True):
file_path = Path(file_path_str)
if file_path.is_file() and _is_readable(file_path):
try:
primitive = parse_primitive_file(file_path, source=source)
collection.add_primitive(primitive)
except Exception as e:
print(f"Warning: Failed to parse dependency primitive {file_path}: {e}")Then the main function becomes:
if apm_dir.exists():
_scan_patterns(apm_dir, DEPENDENCY_PRIMITIVE_PATTERNS, collection, source)
if github_dir.exists():
_scan_patterns(github_dir, DEPENDENCY_GITHUB_PRIMITIVE_PATTERNS, collection, source)This keeps the logic in one place for future maintenance.
2. Missing CHANGELOG entry
Please add an entry under ## [Unreleased] in CHANGELOG.md, e.g.:
### Fixed
- Fix `apm compile --target claude` silently skipping dependency instructions stored in `.github/instructions/` (#631)
Thanks for the contribution!
…only
scan_directory_with_source only scanned {dep}/.apm/ for primitives, so
dependency packages that store instructions in .github/instructions/ were
silently skipped during discover_primitives_with_dependencies. The
discover_primitives path (used by --local-only and --validate) uses
LOCAL_PRIMITIVE_PATTERNS which includes **/.github/instructions/, so
those two modes worked while the normal compile path did not.
Add DEPENDENCY_GITHUB_PRIMITIVE_PATTERNS and scan {dep}/.github/ in
scan_directory_with_source alongside the existing .apm/ scan. The
original early-return when .apm/ was absent is replaced by independent
checks so both .apm/ and .github/ are always considered.
Fixes microsoft#631.
…ft#631) Extract duplicated glob-scan-parse loop into _scan_patterns() so both .apm/ and .github/ directory scanning share a single implementation. Add missing CHANGELOG entry under [Unreleased] for the microsoft#631 fix.
f67705d to
b782402
Compare
|
@sergio-sisternes-epam Thanks for the thorough review! Done — both points addressed in the latest commit (f67705d):
All 63 unit tests still pass. |
There was a problem hiding this comment.
Pull request overview
Fixes the dependency-scanning compile path so .github/instructions/ inside installed dependencies is discovered during normal distributed compilation (e.g., apm compile --target claude without --local-only), matching the behavior of --local-only/--validate.
Changes:
- Extend dependency primitive scanning to also inspect
{dep}/.github/(in addition to{dep}/.apm/) duringdiscover_primitives_with_dependencies. - Refactor dependency scanning into a shared
_scan_patterns()helper to avoid duplicating the glob/parse loop. - Add unit regression tests covering
.github/instructions/discovery for dependencies, and add a changelog entry under Unreleased/Fixed.
Show a summary per file
| File | Description |
|---|---|
src/apm_cli/primitives/discovery.py |
Adds .github/ dependency scanning and refactors scanning loop into a helper. |
tests/unit/primitives/test_discovery_parser.py |
Adds regression tests ensuring dependency instructions in .github/instructions/ are discovered. |
CHANGELOG.md |
Documents the fix under ## [Unreleased] → ### Fixed. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/apm_cli/primitives/discovery.py:350
- Non-ASCII em dash (
—) in this comment violates the repo's printable-ASCII encoding rule and can break Windows cp1252 terminals. Replace it with ASCII (e.g., "-" or "--").
# Also scan .github directory — some packages store primitives there instead of (or
# in addition to) .apm/. Without this, dependency instructions in .github/instructions/
# are silently skipped in the normal compile path (issue #631).
- Files reviewed: 3/3 changed files
- Comments generated: 2
| Args: | ||
| directory (Path): Directory to scan (e.g., apm_modules/package_name). | ||
| base_dir (Path): Directory to scan (e.g., dep/.apm or dep/.github). | ||
| patterns (Dict[str, List[str]]): Primitive-type → glob-pattern mapping. |
There was a problem hiding this comment.
Non-ASCII arrow character (→) in the docstring violates the repo's printable-ASCII encoding rule and may cause encoding errors on some Windows terminals. Replace with an ASCII equivalent like "->".
This issue also appears on line 348 of the same file.
| patterns (Dict[str, List[str]]): Primitive-type → glob-pattern mapping. | |
| patterns (Dict[str, List[str]]): Primitive-type -> glob-pattern mapping. |
|
|
||
| - Pin codex setup to `rust-v0.118.0` for security and reproducibility; update config to `wire_api = "responses"` (#663) | ||
| - Propagate headers and environment variables through OpenCode MCP adapter with defensive copies to prevent mutation (#622) | ||
| - Fix `apm compile --target claude` silently skipping dependency instructions stored in `.github/instructions/` (#631) |
There was a problem hiding this comment.
Changelog formatting: add a blank line between the last bullet in ### Fixed and the next section header (### Changed) to match the surrounding Keep a Changelog style used elsewhere in this file.
| - Fix `apm compile --target claude` silently skipping dependency instructions stored in `.github/instructions/` (#631) | |
| - Fix `apm compile --target claude` silently skipping dependency instructions stored in `.github/instructions/` (#631) |
What
Fix compile path that silently skipped dependency instructions stored in
.github/instructions/when runningapm compile --target claudewithout--local-only.Why
Issue #631:
scan_directory_with_sourceonly scanned{dep}/.apm/forprimitives. Packages that store instructions in
.github/instructions/(instead of
.apm/instructions/) were completely invisible todiscover_primitives_with_dependencies. The--local-onlyand--validatepaths used
LOCAL_PRIMITIVE_PATTERNS(which includes**/.github/instructions/)so they worked, but the normal distributed compile path did not.
Symptoms:
apm compile --target claude --verboseshowedInstruction Processing: 0.0msCLAUDE.mdwas generatedapm compile --target claude --local-onlyworked correctlyapm compile --validatecould find the instructionsHow
Add
DEPENDENCY_GITHUB_PRIMITIVE_PATTERNS(mirroringDEPENDENCY_PRIMITIVE_PATTERNSfor the
.github/directory layout) and scan{dep}/.github/inscan_directory_with_sourcealongside the existing.apm/scan.The original early-return guard
if not apm_dir.exists(): returnis replacedby independent
if apm_dir.exists():/if github_dir.exists():checks soboth directories are always considered regardless of which one is present.
No CLI interface changes. No architecture changes. Existing
.apm/-basedpackages are unaffected.
Test
.github/-only dependency → 0 instructions before fix.github/-only dependency → instruction found andCLAUDE.mdgenerated--local-onlystill works correctly--target copilotunaffected--validateunaffectedTestScanDirectoryWithSource:test_github_instructions_discovered_when_no_apm_dirtest_github_instructions_discovered_alongside_apm_dir